Skip to content

Commit

Permalink
Revert "crypto: add KeyObject.asymmetricKeySize"
Browse files Browse the repository at this point in the history
This reverts commit 4895927.

PR-URL: #26636
Fixes: #26631
Reviewed-By: Ujjwal Sharma <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
tniessen committed Mar 15, 2019
1 parent fe8972a commit 6f77af5
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 39 deletions.
9 changes: 0 additions & 9 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -1121,15 +1121,6 @@ exposes different functions.
Most applications should consider using the new `KeyObject` API instead of
passing keys as strings or `Buffer`s due to improved security features.

### keyObject.asymmetricKeySize
<!-- YAML
added: REPLACEME
-->
* {number}

For asymmetric keys, this property represents the size of the embedded key in
bytes. This property is `undefined` for symmetric keys.

### keyObject.asymmetricKeyType
<!-- YAML
added: v11.6.0
Expand Down
6 changes: 0 additions & 6 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,9 @@ class SecretKeyObject extends KeyObject {
}
}

const kAsymmetricKeySize = Symbol('kAsymmetricKeySize');
const kAsymmetricKeyType = Symbol('kAsymmetricKeyType');

class AsymmetricKeyObject extends KeyObject {
get asymmetricKeySize() {
return this[kAsymmetricKeySize] ||
(this[kAsymmetricKeySize] = this[kHandle].getAsymmetricKeySize());
}

get asymmetricKeyType() {
return this[kAsymmetricKeyType] ||
(this[kAsymmetricKeyType] = this[kHandle].getAsymmetricKeyType());
Expand Down
13 changes: 0 additions & 13 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3329,8 +3329,6 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
t->InstanceTemplate()->SetInternalFieldCount(1);

env->SetProtoMethod(t, "init", Init);
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeySize",
GetAsymmetricKeySize);
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
GetSymmetricKeySize);
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeyType",
Expand Down Expand Up @@ -3376,11 +3374,6 @@ const char* KeyObject::GetSymmetricKey() const {
return this->symmetric_key_.get();
}

size_t KeyObject::GetAsymmetricKeySize() const {
CHECK_NE(key_type_, kKeyTypeSecret);
return EVP_PKEY_size(this->asymmetric_key_.get());
}

size_t KeyObject::GetSymmetricKeySize() const {
CHECK_EQ(key_type_, kKeyTypeSecret);
return this->symmetric_key_len_;
Expand Down Expand Up @@ -3484,12 +3477,6 @@ void KeyObject::GetAsymmetricKeyType(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(key->GetAsymmetricKeyType());
}

void KeyObject::GetAsymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
KeyObject* key;
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
args.GetReturnValue().Set(static_cast<uint32_t>(key->GetAsymmetricKeySize()));
}

void KeyObject::GetSymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
KeyObject* key;
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
Expand Down
4 changes: 0 additions & 4 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ class KeyObject : public BaseObject {
// only be used to implement cryptograohic operations requiring the key.
ManagedEVPPKey GetAsymmetricKey() const;
const char* GetSymmetricKey() const;
size_t GetAsymmetricKeySize() const;
size_t GetSymmetricKeySize() const;

protected:
Expand All @@ -471,9 +470,6 @@ class KeyObject : public BaseObject {
const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Local<v8::String> GetAsymmetricKeyType() const;

static void GetAsymmetricKeySize(
const v8::FunctionCallbackInfo<v8::Value>& args);

static void GetSymmetricKeySize(
const v8::FunctionCallbackInfo<v8::Value>& args);

Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-crypto-key-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
const key = createSecretKey(keybuf);
assert.strictEqual(key.type, 'secret');
assert.strictEqual(key.symmetricKeySize, 32);
assert.strictEqual(key.asymmetricKeySize, undefined);
assert.strictEqual(key.asymmetricKeyType, undefined);

const exportedKey = key.export();
Expand Down Expand Up @@ -92,13 +91,11 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
const publicKey = createPublicKey(publicPem);
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.strictEqual(publicKey.asymmetricKeySize, 128);
assert.strictEqual(publicKey.symmetricKeySize, undefined);

const privateKey = createPrivateKey(privatePem);
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.strictEqual(privateKey.asymmetricKeySize, 128);
assert.strictEqual(privateKey.symmetricKeySize, undefined);

// It should be possible to derive a public key from a private key.
Expand Down
4 changes: 0 additions & 4 deletions test/parallel/test-crypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.strictEqual(publicKey.asymmetricKeySize, 64);

assert.strictEqual(typeof privateKey, 'object');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.strictEqual(publicKey.asymmetricKeySize, 64);
}

{
Expand Down Expand Up @@ -455,7 +453,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.strictEqual(publicKey.asymmetricKeySize, 128);

// The private key should still be a string.
assert.strictEqual(typeof privateKey, 'string');
Expand All @@ -480,7 +477,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert.strictEqual(typeof privateKey, 'object');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.strictEqual(privateKey.asymmetricKeySize, 128);

testEncryptDecrypt(publicKey, privateKey);
testSignVerify(publicKey, privateKey);
Expand Down

0 comments on commit 6f77af5

Please sign in to comment.