New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ursa-purejs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ursa-purejs - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

68

lib/ursa.js

@@ -216,11 +216,15 @@ // Copyright 2012 The Obvious Corporation.

var buf = new Buffer(4);
buf.writeUInt32BE(rsa.keyPair.e);
return encodeBuffer(buf, encoding);
buf.writeUInt32BE(rsa.keyPair.e, 0);
var i = 0;
while (i < buf.length - 1 && buf[i] == 0)
i++;
return encodeBuffer(buf.slice(i), encoding);
}
function getModulus(encoding) {
var buf = new Buffer(4);
// TODO : How do I get modulus ?
throw new Error("Unsupported method : getModulus");
//return encodeBuffer(rsa.getModulus(), encoding);
var buf = rsa.keyPair.n.toBuffer();
var i = 0;
while (i < buf.length - 1 && buf[i] == 0)
i++;
return encodeBuffer(buf.slice(i), encoding);
}

@@ -233,11 +237,7 @@

function toPublicSsh(encoding) {
// TODO : fix modulus
throw new Error("Unsupported method : toPublicSsh");
//return encodeBuffer(createSshPublicKey(rsa), encoding);
return encodeBuffer(createSshPublicKey(this), encoding);
}
function toPublicSshFingerprint(encoding) {
// TODO : fix modulus
throw new Error("Unsupported method : toPublicSsh");
// return sshFingerprint(createSshPublicKey(rsa), undefined, encoding);
return sshFingerprint(createSshPublicKey(this), undefined, encoding);
}

@@ -260,14 +260,17 @@

//algorithm = textToNid(algorithm);
hash = decodeString(hash, encoding);
throw new Error("Unsupported operation : verify");
/* hash = decodeString(hash, encoding);
sig = decodeString(sig, encoding);
rsa.setOptions({ 'signingScheme': 'pkcs1-' + algorithm });
console.log(rsa);
console.log(algorithm);
return rsa.verify(hash, sig);
return rsa.verify(hash, sig);*/
}
function hashAndVerify(algorithm, buf, sig, encoding) {
var verifier = createVerifier(algorithm);
var hash = decodeString(buf, encoding);
sig = decodeString(sig, encoding);
rsa.setOptions({ 'signingScheme': 'pkcs1-' + algorithm });
return rsa.verify(hash, sig);
/*var verifier = createVerifier(algorithm);
verifier.update(buf, encoding);
return verifier.verify(self, sig, encoding);
return verifier.verify(self, sig, encoding);*/
}

@@ -295,2 +298,9 @@

function addTrailingEOL(str) {
if (str.indexOf("\n", str.length - 1) === -1)
return (str + "\n");
else
return (str);
}
/**

@@ -305,3 +315,3 @@ * Private Key object. This is the externally-visible object that one

function toPrivatePem(encoding) {
return encodeBuffer(rsa.getPrivatePEM(), encoding);
return encodeBuffer(addTrailingEOL(rsa.exportKey()), encoding);
}

@@ -317,3 +327,3 @@

function privateEncrypt(buf, bufEncoding, outEncoding) {
throw new Exception("Unsupported operation : Private encrypt");
throw new Error("Unsupported operation : Private encrypt");
buf = decodeString(buf, bufEncoding);

@@ -325,11 +335,15 @@ return encodeBuffer(rsa.privateEncrypt(buf), outEncoding);

//algorithm = textToNid(algorithm);
hash = decodeString(hash, hashEncoding);
rsa.options.signingAlgorithm = algorithm;
return encodeBuffer(rsa.sign(hash), outEncoding);
throw new Error("Unsupported operation : sign");
/*hash = decodeString(hash, hashEncoding);
rsa.setOptions({ signingScheme: "pkcs1-" + algorithm });
return encodeBuffer(rsa.sign(hash), outEncoding);*/
}
function hashAndSign(algorithm, buf, bufEncoding, outEncoding) {
var signer = createSigner(algorithm);
var hash = decodeString(buf, bufEncoding);
rsa.setOptions({ signingScheme: "pkcs1-" + algorithm });
return encodeBuffer(rsa.sign(hash), outEncoding);
/* var signer = createSigner(algorithm);
signer.update(buf, bufEncoding);
return signer.sign(self, outEncoding);
return signer.sign(self, outEncoding);*/
}

@@ -358,3 +372,3 @@

try {
rsa.importKey(pem);
rsa.importKey(pem, 'public');
} catch (ex) {

@@ -386,3 +400,3 @@ if (!isPublicKeyPem(pem)) {

} else {
rsa.importKey(pem);
rsa.importKey(pem, 'private');
}

@@ -389,0 +403,0 @@ } catch (ex) {

{
"name": "ursa-purejs",
"version": "0.0.1",
"version": "0.0.2",
"description": "A pure-js drop-in replacement for URSA, using node-rsa",

@@ -28,4 +28,4 @@ "main": "lib/ursa.js",

"dependencies": {
"node-rsa": "^0.2.13"
"node-rsa": "^0.2.23"
}
}

@@ -297,3 +297,2 @@ ursa-purejs

NOT YET IMPLEMENTED
Get the public modulus as an unsigned big-endian byte sequence.

@@ -303,3 +302,2 @@

NOT YET IMPLEMENTED
This is a friendly wrapper for verifying signatures. The given buffer

@@ -334,3 +332,2 @@ is hashed using the named algorithm, and the result is verified

NOT YET IMPLEMENTED
This converts the public key data into an SSH-format file. This is the

@@ -351,3 +348,2 @@ file format one finds in SSH's `authorized_keys` and `known_hosts` files.

NOT YET IMPLEMENTED
Return the SSH-style public key fingerprint of this key. See

@@ -408,3 +404,2 @@ `ursa.sshFingerprint()`, above, for more details.

NOT YET IMPLEMENTED
This is a friendly wrapper for producing signatures. The given buffer

@@ -411,0 +406,0 @@ is hashed using the named algorithm, and the result is signed using

@@ -42,4 +42,4 @@ // Copyright 2012 The Obvious Corporation.

var PASSWORD = new Buffer("biscuits", UTF8);
// TODO : Make this 8-bit to match node-rsa
var EXPONENT_HEX = "00010001";
var EXPONENT_HEX = "010001";
var MODULUS_HEX =

@@ -46,0 +46,0 @@ "ae0a2fd0a1d56253ad4b5e7f5883b41e9cfd348b964221fff55b82aa3127b0c2" +

@@ -47,4 +47,3 @@ // Copyright 2012 The Obvious Corporation.

function test_getModulus(key) {
// TODO : get modulus
/*var buf = key.getModulus();
var buf = key.getModulus();
assert.equal(buf.toString(fixture.HEX), fixture.MODULUS_HEX);

@@ -62,3 +61,3 @@

result = key.getModulus(fixture.UTF8);
assert.equal(result, buf.toString(fixture.UTF8));*/
assert.equal(result, buf.toString(fixture.UTF8));
}

@@ -76,4 +75,3 @@

function test_toPublicSsh(key) {
// TODO : Depends on modulus fix
/*var keyString = fixture.SSH_PUBLIC_KEY.toString(fixture.BASE64);
var keyString = fixture.SSH_PUBLIC_KEY.toString(fixture.BASE64);
var result = key.toPublicSsh().toString(fixture.BASE64);

@@ -83,12 +81,11 @@ assert.equal(result, keyString);

result = key.toPublicSsh(fixture.BASE64);
assert.equal(result, keyString);*/
assert.equal(result, keyString);
}
function test_toPublicSshFingerprint(key) {
// TODO : See above
/*var result = key.toPublicSshFingerprint().toString(fixture.HEX);
var result = key.toPublicSshFingerprint().toString(fixture.HEX);
assert.equal(result, fixture.SSH_PUBLIC_KEY_FINGERPRINT_HEX);
result = key.toPublicSshFingerprint(fixture.HEX);
assert.equal(result, fixture.SSH_PUBLIC_KEY_FINGERPRINT_HEX);*/
assert.equal(result, fixture.SSH_PUBLIC_KEY_FINGERPRINT_HEX);
}

@@ -124,3 +121,3 @@

function test_verify(key) {
assert.equal(key.verify(fixture.SHA256, fixture.PLAINTEXT_SHA256,
/*assert.equal(key.verify(fixture.SHA256, fixture.PLAINTEXT_SHA256,
fixture.PLAINTEXT_SHA256_SIGNATURE,

@@ -131,3 +128,3 @@ fixture.HEX), true);

var sig = new Buffer(fixture.PLAINTEXT_SHA256_SIGNATURE, fixture.HEX);
assert.equal(key.verify(fixture.SHA256, hash, sig), true);
assert.equal(key.verify(fixture.SHA256, hash, sig), true);*/
}

@@ -165,3 +162,3 @@

function test_toEncryptedPrivatePem(key) {
var password = fixture.PASSWORD.toString(fixture.UTF8);
/*var password = fixture.PASSWORD.toString(fixture.UTF8);
var cipher = fixture.DES_EDE3_CBC;

@@ -179,3 +176,3 @@

plainTextKey = ursa.createPrivateKey(pem, password);
assertStringEqual(plainTextKey.toPrivatePem().toString(), fixture.PRIVATE_KEY.toString());
assertStringEqual(plainTextKey.toPrivatePem().toString(), fixture.PRIVATE_KEY.toString());*/
}

@@ -194,3 +191,3 @@

function test_privateEncrypt(key) {
var encoded = key.privateEncrypt(
/*var encoded = key.privateEncrypt(
new Buffer(fixture.PLAINTEXT, fixture.UTF8)).toString(fixture.HEX);

@@ -203,7 +200,7 @@ assert.equal(encoded, fixture.PUBLIC_CIPHERTEXT_HEX);

encoded = key.privateEncrypt(fixture.PLAINTEXT, undefined, fixture.HEX);
assert.equal(encoded, fixture.PUBLIC_CIPHERTEXT_HEX);
assert.equal(encoded, fixture.PUBLIC_CIPHERTEXT_HEX);*/
}
function test_sign(key) {
var sig = key.sign(fixture.SHA256,
/*var sig = key.sign(fixture.SHA256,
fixture.PLAINTEXT_SHA256, fixture.HEX,

@@ -216,3 +213,3 @@ fixture.BASE64);

sig = key.sign(fixture.SHA256, buf, undefined, fixture.HEX);
assert.equal(sig, fixture.PLAINTEXT_SHA256_SIGNATURE);
assert.equal(sig, fixture.PLAINTEXT_SHA256_SIGNATURE);*/
}

@@ -325,7 +322,6 @@

// extra failures added at the high level.
// TODO : fix this, breaks for some reason
/*function f1() {
function f1() {
console.log(ursa.createPublicKey(fixture.PRIVATE_KEY));
}
assert.throws(f1, /Not a public key\./);*/
assert.throws(f1, /Not a public key\./);
}

@@ -336,8 +332,6 @@

// extra failures added at the high level.
// TODO : fix this, breaks for some reason
/*
function f1() {
ursa.createPrivateKey(fixture.PUBLIC_KEY);
}
assert.throws(f1, /Not a private key\./);*/
assert.throws(f1, /Not a private key\./);
}

@@ -415,12 +409,11 @@

// TODO : breaks
/*function f4() {
function f4() {
ursa.coercePrivateKey(fixture.PUBLIC_KEY);
}
assert.throws(f4, /Not a private key/);*/
assert.throws(f4, /Not a private key/);
/*function f5() {
function f5() {
ursa.coercePrivateKey(fixture.PUBLIC_KEY.toString());
}
assert.throws(f5, /Not a private key/);*/
assert.throws(f5, /Not a private key/);
}

@@ -444,4 +437,3 @@

// TODO : breaks
/*function f4() {
function f4() {
ursa.coercePublicKey(fixture.PRIVATE_KEY);

@@ -454,3 +446,3 @@ }

}
assert.throws(f5, /Not a public key/);*/
assert.throws(f5, /Not a public key/);
}

@@ -549,3 +541,3 @@

function testSigner() {
var key = ursa.createPrivateKey(fixture.PRIVATE_KEY);
/*var key = ursa.createPrivateKey(fixture.PRIVATE_KEY);
var signer = ursa.createSigner(fixture.SHA256);

@@ -557,7 +549,7 @@

assert.equal(sig, fixture.PLAINTEXT_SHA256_SIGNATURE);
assert.equal(sig, fixture.PLAINTEXT_SHA256_SIGNATURE);*/
}
function testVerifier() {
var key = ursa.createPublicKey(fixture.PUBLIC_KEY);
/*var key = ursa.createPublicKey(fixture.PUBLIC_KEY);
var verifier = ursa.createVerifier(fixture.SHA256);

@@ -572,10 +564,11 @@ verifier.update(fixture.PLAINTEXT, fixture.UTF8);

var sigBuf = new Buffer(fixture.PLAINTEXT_SHA256_SIGNATURE, fixture.HEX);
assert.equal(verifier.verify(key, sigBuf), true);
assert.equal(verifier.verify(key, sigBuf), true);*/
}
function test_openSshPublicKey() {
var sshKey = ursa.openSshPublicKey(fixture.SSH_PUBLIC_KEY),
// TODO : Implement this ?
/* var sshKey = ursa.openSshPublicKey(fixture.SSH_PUBLIC_KEY),
pubKey = ursa.createPublicKey(fixture.PUBLIC_KEY);
assert.equal(ursa.equalKeys(sshKey, pubKey), true);
assert.equal(ursa.equalKeys(sshKey, pubKey), true);*/
}

@@ -582,0 +575,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc