summaryrefslogtreecommitdiff
path: root/src/crypto_key.cc
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-14 22:54:33 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-14 22:54:33 +0900
commita1f7b009810cd94c3d43752ae035d4ff123dd4de (patch)
treeae6cd7ce9fe189e47d105d26845821c5bd6667a2 /src/crypto_key.cc
parentNew translations ja-JP.yml (German) (#4683) (diff)
downloadsharkey-a1f7b009810cd94c3d43752ae035d4ff123dd4de.tar.gz
sharkey-a1f7b009810cd94c3d43752ae035d4ff123dd4de.tar.bz2
sharkey-a1f7b009810cd94c3d43752ae035d4ff123dd4de.zip
Clean up
Diffstat (limited to 'src/crypto_key.cc')
-rw-r--r--src/crypto_key.cc111
1 files changed, 0 insertions, 111 deletions
diff --git a/src/crypto_key.cc b/src/crypto_key.cc
deleted file mode 100644
index 658586baed..0000000000
--- a/src/crypto_key.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <nan.h>
-#include <openssl/bio.h>
-#include <openssl/buffer.h>
-#include <openssl/crypto.h>
-#include <openssl/pem.h>
-#include <openssl/rsa.h>
-#include <openssl/x509.h>
-
-NAN_METHOD(extractPublic)
-{
- const auto sourceString = info[0]->ToString(Nan::GetCurrentContext()).ToLocalChecked();
- if (!sourceString->IsOneByte()) {
- Nan::ThrowError("Malformed character found");
- return;
- }
-
- size_t sourceLength = sourceString->Length();
- const auto sourceBuf = new char[sourceLength];
-
- Nan::DecodeWrite(sourceBuf, sourceLength, sourceString);
-
- const auto source = BIO_new_mem_buf(sourceBuf, sourceLength);
- if (source == nullptr) {
- Nan::ThrowError("Memory allocation failed");
- delete[] sourceBuf;
- return;
- }
-
- const auto rsa = PEM_read_bio_RSAPrivateKey(source, nullptr, nullptr, nullptr);
-
- BIO_free(source);
- delete[] sourceBuf;
-
- if (rsa == nullptr) {
- Nan::ThrowError("Decode failed");
- return;
- }
-
- const auto destination = BIO_new(BIO_s_mem());
- if (destination == nullptr) {
- Nan::ThrowError("Memory allocation failed");
- return;
- }
-
- const auto result = PEM_write_bio_RSAPublicKey(destination, rsa);
-
- RSA_free(rsa);
-
- if (result != 1) {
- Nan::ThrowError("Public key extraction failed");
- BIO_free(destination);
- return;
- }
-
- char *pem;
- const auto pemLength = BIO_get_mem_data(destination, &pem);
-
- info.GetReturnValue().Set(Nan::Encode(pem, pemLength));
- BIO_free(destination);
-}
-
-NAN_METHOD(generate)
-{
- const auto exponent = BN_new();
- const auto mem = BIO_new(BIO_s_mem());
- const auto rsa = RSA_new();
- char *data;
- long result;
-
- if (exponent == nullptr || mem == nullptr || rsa == nullptr) {
- Nan::ThrowError("Memory allocation failed");
- goto done;
- }
-
- result = BN_set_word(exponent, 65537);
- if (result != 1) {
- Nan::ThrowError("Exponent setting failed");
- goto done;
- }
-
- result = RSA_generate_key_ex(rsa, 2048, exponent, nullptr);
- if (result != 1) {
- Nan::ThrowError("Key generation failed");
- goto done;
- }
-
- result = PEM_write_bio_RSAPrivateKey(mem, rsa, NULL, NULL, 0, NULL, NULL);
- if (result != 1) {
- Nan::ThrowError("Key export failed");
- goto done;
- }
-
- result = BIO_get_mem_data(mem, &data);
- info.GetReturnValue().Set(Nan::Encode(data, result));
-
-done:
- RSA_free(rsa);
- BIO_free(mem);
- BN_free(exponent);
-}
-
-NAN_MODULE_INIT(InitAll)
-{
- Nan::Set(target, Nan::New<v8::String>("extractPublic").ToLocalChecked(),
- Nan::GetFunction(Nan::New<v8::FunctionTemplate>(extractPublic)).ToLocalChecked());
-
- Nan::Set(target, Nan::New<v8::String>("generate").ToLocalChecked(),
- Nan::GetFunction(Nan::New<v8::FunctionTemplate>(generate)).ToLocalChecked());
-}
-
-NODE_MODULE(crypto_key, InitAll);