@@ -3581,186 +3581,6 @@ void GetHashes(const FunctionCallbackInfo<Value>& args) {
35813581}
35823582
35833583
3584- void Certificate::Initialize (Handle<Object> target) {
3585- HandleScope scope (node_isolate);
3586-
3587- Local<FunctionTemplate> t = FunctionTemplate::New (New);
3588-
3589- t->InstanceTemplate ()->SetInternalFieldCount (1 );
3590-
3591- NODE_SET_PROTOTYPE_METHOD (t, " verifySpkac" , VerifySpkac);
3592- NODE_SET_PROTOTYPE_METHOD (t, " exportPublicKey" , ExportPublicKey);
3593- NODE_SET_PROTOTYPE_METHOD (t, " exportChallenge" , ExportChallenge);
3594-
3595- target->Set (FIXED_ONE_BYTE_STRING (node_isolate, " Certificate" ),
3596- t->GetFunction ());
3597- }
3598-
3599-
3600- void Certificate::New (const FunctionCallbackInfo<Value>& args) {
3601- new Certificate (args.GetIsolate (), args.This ());
3602- }
3603-
3604-
3605- bool Certificate::VerifySpkac (const char * data, unsigned int len) {
3606- bool rc = false ;
3607- EVP_PKEY* pkey = NULL ;
3608- NETSCAPE_SPKI* spki = NULL ;
3609-
3610- spki = NETSCAPE_SPKI_b64_decode (data, len);
3611- if (spki == NULL )
3612- goto exit;
3613-
3614- pkey = X509_PUBKEY_get (spki->spkac ->pubkey );
3615- if (pkey == NULL )
3616- goto exit;
3617-
3618- rc = NETSCAPE_SPKI_verify (spki, pkey) > 0 ;
3619-
3620- exit:
3621- if (pkey != NULL )
3622- EVP_PKEY_free (pkey);
3623-
3624- if (spki != NULL )
3625- NETSCAPE_SPKI_free (spki);
3626-
3627- return rc;
3628- }
3629-
3630-
3631- void Certificate::VerifySpkac (const FunctionCallbackInfo<Value>& args) {
3632- HandleScope scope (node_isolate);
3633-
3634- Certificate* certificate = WeakObject::Unwrap<Certificate>(args.This ());
3635- bool rc = false ;
3636-
3637- if (args.Length () < 1 )
3638- return ThrowTypeError (" Missing argument" );
3639-
3640- ASSERT_IS_BUFFER (args[0 ]);
3641-
3642- size_t length = Buffer::Length (args[0 ]);
3643- if (length == 0 )
3644- return args.GetReturnValue ().Set (false );
3645-
3646- const char * data = Buffer::Data (args[0 ]);
3647- assert (data != NULL );
3648-
3649- rc = certificate->VerifySpkac (data, length) > 0 ;
3650-
3651- args.GetReturnValue ().Set (rc);
3652- }
3653-
3654-
3655- const char * Certificate::ExportPublicKey (const char * data, unsigned int len) {
3656- char * buf = NULL ;
3657- EVP_PKEY* pkey = NULL ;
3658- NETSCAPE_SPKI* spki = NULL ;
3659-
3660- BIO* bio = BIO_new (BIO_s_mem ());
3661- if (bio == NULL )
3662- goto exit;
3663-
3664- spki = NETSCAPE_SPKI_b64_decode (data, len);
3665- if (spki == NULL )
3666- goto exit;
3667-
3668- pkey = NETSCAPE_SPKI_get_pubkey (spki);
3669- if (pkey == NULL )
3670- goto exit;
3671-
3672- if (PEM_write_bio_PUBKEY (bio, pkey) <= 0 )
3673- goto exit;
3674-
3675- BUF_MEM* ptr;
3676- BIO_get_mem_ptr (bio, &ptr);
3677-
3678- buf = new char [ptr->length ];
3679- memcpy (buf, ptr->data , ptr->length );
3680-
3681- exit:
3682- if (pkey != NULL )
3683- EVP_PKEY_free (pkey);
3684-
3685- if (spki != NULL )
3686- NETSCAPE_SPKI_free (spki);
3687-
3688- if (bio != NULL )
3689- BIO_free_all (bio);
3690-
3691- return buf;
3692- }
3693-
3694-
3695- void Certificate::ExportPublicKey (const FunctionCallbackInfo<Value>& args) {
3696- HandleScope scope (node_isolate);
3697-
3698- Certificate* certificate = WeakObject::Unwrap<Certificate>(args.This ());
3699-
3700- if (args.Length () < 1 )
3701- return ThrowTypeError (" Missing argument" );
3702-
3703- ASSERT_IS_BUFFER (args[0 ]);
3704-
3705- size_t length = Buffer::Length (args[0 ]);
3706- if (length == 0 )
3707- return args.GetReturnValue ().SetEmptyString ();
3708-
3709- char * data = Buffer::Data (args[0 ]);
3710- assert (data != NULL );
3711-
3712- const char * pkey = certificate->ExportPublicKey (data, length);
3713- if (pkey == NULL )
3714- return args.GetReturnValue ().SetEmptyString ();
3715-
3716- Local<Value> out = Encode (pkey, strlen (pkey), BUFFER);
3717-
3718- delete[] pkey;
3719-
3720- args.GetReturnValue ().Set (out);
3721- }
3722-
3723-
3724- const char * Certificate::ExportChallenge (const char * data, unsigned int len) {
3725- NETSCAPE_SPKI* sp = NULL ;
3726-
3727- sp = NETSCAPE_SPKI_b64_decode (data, len);
3728- if (sp == NULL )
3729- return NULL ;
3730-
3731- return reinterpret_cast <const char *>(ASN1_STRING_data (sp->spkac ->challenge ));
3732- }
3733-
3734-
3735- void Certificate::ExportChallenge (const FunctionCallbackInfo<Value>& args) {
3736- HandleScope scope (node_isolate);
3737-
3738- Certificate* crt = WeakObject::Unwrap<Certificate>(args.This ());
3739-
3740- if (args.Length () < 1 )
3741- return ThrowTypeError (" Missing argument" );
3742-
3743- ASSERT_IS_BUFFER (args[0 ]);
3744-
3745- size_t len = Buffer::Length (args[0 ]);
3746- if (len == 0 )
3747- return args.GetReturnValue ().SetEmptyString ();
3748-
3749- char * data = Buffer::Data (args[0 ]);
3750- assert (data != NULL );
3751-
3752- const char * cert = crt->ExportChallenge (data, len);
3753- if (cert == NULL )
3754- return args.GetReturnValue ().SetEmptyString ();
3755-
3756- Local<Value> outString = Encode (cert, strlen (cert), BUFFER);
3757-
3758- delete[] cert;
3759-
3760- args.GetReturnValue ().Set (outString);
3761- }
3762-
3763-
37643584void InitCryptoOnce () {
37653585 SSL_library_init ();
37663586 OpenSSL_add_all_algorithms ();
@@ -3801,7 +3621,6 @@ void InitCrypto(Handle<Object> target,
38013621 Hash::Initialize (env, target);
38023622 Sign::Initialize (env, target);
38033623 Verify::Initialize (env, target);
3804- Certificate::Initialize (target);
38053624
38063625 NODE_SET_METHOD (target, " PBKDF2" , PBKDF2);
38073626 NODE_SET_METHOD (target, " randomBytes" , RandomBytes<false >);
0 commit comments