<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Button = require('../components/button')
const aboutActions = require('./aboutActions')
const windowConstants = require('../constants/windowConstants')
const messages = require('../constants/messages')
const ipc = window.chrome.ipcRenderer

require('../../less/button.less')
require('../../less/window.less')
require('../../less/about/error.less')

function toHexString (byteArray) {
  return byteArray.map(function (byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2)
  }).join(':')
}

function toByteArray (str) {
  var bytes = []
  for (var i = 0; i < str.length; ++i) {
    bytes.push(str.charCodeAt(i))
  }
  return bytes
}

function seperateHex (hexStr) {
  var result = []
  for (var i = 0; i < hexStr.length; ++i) {
    result += hexStr[i]
    if (i % 2 && i !== hexStr.length - 1) {
      result += ':'
    }
  }
  return result
}

class CertErrorPage extends React.Component {
  constructor () {
    super()
    this.state = {
      advanced: false,
      certDetail: false,
      certIssuerName: null,
      certSubjectName: null,
      certSerialNumber: null,
      certValidStart: null,
      certValidExpiry: null,
      certFingerprint: null
    }

    ipc.on(messages.SET_CERT_ERROR_DETAIL, (e, detail) => {
      var validStart = new Date()
      var validExpiry = new Date()
      validStart.setTime(detail.validStart * 1000)
      validExpiry.setTime(detail.validExpiry * 1000)
      this.setState({
        certDetail: true,
        certIssuerName: detail.issuerName,
        certSubjectName: detail.subjectName,
        certSerialNumber: seperateHex(detail.serialNumber),
        certValidStart: validStart.toString(),
        certValidExpiry: validExpiry.toString(),
        certFingerprint: detail.fingerprint.split('/')
      })
    })
  }

  onAccept () {
    aboutActions.acceptCertError(this.state.url)
    aboutActions.dispatchAction({
      actionType: windowConstants.WINDOW_SET_URL,
      location: this.state.url,
      key: this.state.frameKey
    })
  }

  onSafety () {
    aboutActions.dispatchAction({
      actionType: windowConstants.WINDOW_SET_URL,
      location: this.state.previousLocation,
      key: this.state.frameKey
    })
  }<commit_msg>Handle cert fingerprints that contain '/'<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Button = require('../components/button')
const aboutActions = require('./aboutActions')
const windowConstants = require('../constants/windowConstants')
const messages = require('../constants/messages')
const ipc = window.chrome.ipcRenderer

require('../../less/button.less')
require('../../less/window.less')
require('../../less/about/error.less')

function toHexString (byteArray) {
  return byteArray.map(function (byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2)
  }).join(':')
}

function toByteArray (str) {
  var bytes = []
  for (var i = 0; i < str.length; ++i) {
    bytes.push(str.charCodeAt(i))
  }
  return bytes
}

function seperateHex (hexStr) {
  var result = []
  for (var i = 0; i < hexStr.length; ++i) {
    result += hexStr[i]
    if (i % 2 && i !== hexStr.length - 1) {
      result += ':'
    }
  }
  return result
}

class CertErrorPage extends React.Component {
  constructor () {
    super()
    this.state = {
      advanced: false,
      certDetail: false,
      certIssuerName: null,
      certSubjectName: null,
      certSerialNumber: null,
      certValidStart: null,
      certValidExpiry: null,
      certFingerprint: null
    }

    ipc.on(messages.SET_CERT_ERROR_DETAIL, (e, detail) => {
      var validStart = new Date()
      var validExpiry = new Date()
      validStart.setTime(detail.validStart * 1000)
      validExpiry.setTime(detail.validExpiry * 1000)
      var fingerprint = detail.fingerprint.split('/')
      var algorithm = fingerprint.shift()
      this.setState({
        certDetail: true,
        certIssuerName: detail.issuerName,
        certSubjectName: detail.subjectName,
        certSerialNumber: seperateHex(detail.serialNumber),
        certValidStart: validStart.toString(),
        certValidExpiry: validExpiry.toString(),
        certFingerprint: [algorithm, fingerprint.join('/')]
      })
    })
  }

  onAccept () {
    aboutActions.acceptCertError(this.state.url)
    aboutActions.dispatchAction({
      actionType: windowConstants.WINDOW_SET_URL,
      location: this.state.url,
      key: this.state.frameKey
    })
  }

  onSafety () {
    aboutActions.dispatchAction({
      actionType: windowConstants.WINDOW_SET_URL,
      location: this.state.previousLocation,
      key: this.state.frameKey
    })
  }
{'fraction_non_alphanumeric': 0.13464207812809836, 'fraction_numerical': 0.008328375966686495, 'mean_word_length': 2.9810576164167326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6573403', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1558, 'n_words': 362}