paypro: convert root certs to hash table in build file.
This commit is contained in:
parent
cc7657d843
commit
8725516afb
|
@ -14,10 +14,20 @@ pushd lib &> /dev/null
|
|||
|
||||
sed -i '$s/,$//g' RootCerts.js
|
||||
|
||||
echo "module.exports = ["$'\n'"$(cat RootCerts.js)" > RootCerts.js
|
||||
echo "var RootCerts = ["$'\n'"$(cat RootCerts.js)" > RootCerts.js
|
||||
echo "];" >> RootCerts.js
|
||||
|
||||
sed -i 's/^"/+ "/g' RootCerts.js
|
||||
sed -i 's/^+ "-----B/"-----B/g' RootCerts.js
|
||||
|
||||
cat <<EOF > RootCerts.js
|
||||
// Use hash table for efficiency:
|
||||
RootCerts = RootCerts.reduce(function(trusted, cert) {
|
||||
cert = cert.replace(/\s+/g, '');
|
||||
trusted[cert] = true;
|
||||
return trusted;
|
||||
}, {});
|
||||
module.exports = RootCerts;
|
||||
EOF
|
||||
|
||||
popd &> /dev/null
|
||||
|
|
|
@ -3,14 +3,7 @@ var protobufjs = protobufjs || require('protobufjs/dist/ProtoBuf');
|
|||
var Message = Message || require('./Message');
|
||||
|
||||
var KJUR = require('jsrsasign');
|
||||
var Trusted = require('./RootCerts');
|
||||
|
||||
// Use hash table for efficiency:
|
||||
Trusted = Trusted.reduce(function(trusted, cert) {
|
||||
cert = cert.replace(/\s+/g, '');
|
||||
trusted[cert] = true;
|
||||
return trusted;
|
||||
}, {});
|
||||
var RootCerts = require('./RootCerts');
|
||||
|
||||
// BIP 70 - payment protocol
|
||||
function PayPro() {
|
||||
|
@ -227,7 +220,7 @@ PayPro.prototype.sign = function(key) {
|
|||
var trusted = [].concat(pki_data).every(function(cert) {
|
||||
var der = cert.toString('hex');
|
||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||
return !!Trusted[pem.replace(/\s+/g, '')];
|
||||
return !!RootCerts[pem.replace(/\s+/g, '')];
|
||||
});
|
||||
|
||||
if (!trusted) {
|
||||
|
@ -272,7 +265,7 @@ PayPro.prototype.verify = function() {
|
|||
var der = cert.toString('hex');
|
||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||
|
||||
if (!Trusted[pem.replace(/\s+/g, '')]) {
|
||||
if (!RootCerts[pem.replace(/\s+/g, '')]) {
|
||||
// throw new Error('Unstrusted certificate.');
|
||||
}
|
||||
|
||||
|
|
|
@ -4,14 +4,7 @@ var Key = require('./Key');
|
|||
var KJUR = require('./x509');
|
||||
var assert = require('assert');
|
||||
var PayPro = require('../PayPro');
|
||||
var Trusted = require('../RootCerts');
|
||||
|
||||
// Use hash table for efficiency:
|
||||
Trusted = Trusted.reduce(function(trusted, cert) {
|
||||
cert = cert.replace(/\s+/g, '');
|
||||
trusted[cert] = true;
|
||||
return trusted;
|
||||
}, {});
|
||||
var RootCerts = require('../RootCerts');
|
||||
|
||||
PayPro.sign = function(key) {
|
||||
if (this.messageType !== 'PaymentRequest')
|
||||
|
@ -32,7 +25,7 @@ PayPro.sign = function(key) {
|
|||
var trusted = [].concat(pki_data).every(function(cert) {
|
||||
var der = cert.toString('hex');
|
||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||
return !!Trusted[pem.replace(/\s+/g, '')];
|
||||
return !!RootCerts[pem.replace(/\s+/g, '')];
|
||||
});
|
||||
|
||||
if (!trusted) {
|
||||
|
@ -82,7 +75,7 @@ PayPro.verify = function() {
|
|||
var der = cert.toString('hex');
|
||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||
|
||||
if (!Trusted[pem.replace(/\s+/g, '')]) {
|
||||
if (!RootCerts[pem.replace(/\s+/g, '')]) {
|
||||
// throw new Error('Unstrusted certificate.');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue