aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-05 19:48:17 +0100
committerTeddy Wing2018-11-05 19:48:17 +0100
commit01bfe227cc257abd0d98d727d22efb5b7ccef0b8 (patch)
tree9ce08f700516c077e7c96cf0c41f6f0f4c331ef0
parent60ad613c7ca8abfcdc5f83d50c3c64c2385296bb (diff)
downloaddome-key-web-01bfe227cc257abd0d98d727d22efb5b7ccef0b8.tar.bz2
aquatic-prime: Try to encrypt input data string
Take the data string we created and feed it through RSA encryption. Basically following the steps used by the Aquatic Prime CLI program written in C: https://github.com/bdrister/AquaticPrime/blob/4f86666/Source/PHP/AquaticPrimeCLI.c At first I tried using a `Signer`, but it looks like I'm supposed to be encrypting the data instead. Unfortunately, I'm now getting this error when calling `private_encrypt()`: 'failed to encrypt: ErrorStack([Error { code: 67526721, library: "rsa routines", function: "RSA_EAY_PRIVATE_ENCRYPT", reason: "malloc failure", file: "rsa_eay.c", line: 368 }])', libcore/result.rs:945:5 Not sure what the problem is yet.
-rw-r--r--license-generator/aquatic-prime/src/lib.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/license-generator/aquatic-prime/src/lib.rs b/license-generator/aquatic-prime/src/lib.rs
index f92ad30..80db363 100644
--- a/license-generator/aquatic-prime/src/lib.rs
+++ b/license-generator/aquatic-prime/src/lib.rs
@@ -2,6 +2,14 @@ extern crate openssl;
use std::collections::HashMap;
+use openssl::bn::BigNum;
+use openssl::hash::MessageDigest;
+use openssl::rsa::Padding;
+use openssl::pkey::PKey;
+use openssl::rsa::RsaPrivateKeyBuilder;
+use openssl::sha::sha1;
+use openssl::sign::Signer;
+
struct AquaticPrime<'a> {
public_key: &'a str,
private_key: &'a str,
@@ -20,7 +28,37 @@ impl<'a> AquaticPrime<'a> {
.collect::<Vec<&str>>()
.concat();
- println!("{:?}", data);
+ let public_key = BigNum::from_hex_str(self.public_key).unwrap();
+ let private_key = BigNum::from_hex_str(self.private_key).unwrap();
+ let rsa_e = BigNum::from_u32(3).unwrap();
+
+ if public_key.num_bits() != 1024 {
+ // TODO: Return Err
+ }
+
+ let digest = sha1(data.as_bytes());
+
+ let keypair = RsaPrivateKeyBuilder::new(
+ public_key,
+ rsa_e,
+ private_key,
+ ).expect("failed to build RSA key").build();
+
+ let mut signature = [0; 128];
+ keypair.private_encrypt(
+ &digest,
+ &mut signature,
+ Padding::PKCS1,
+ ).expect("failed to encrypt");
+
+
+ // let keypair = PKey::from_rsa(keypair).unwrap();
+ //
+ // let mut signer = Signer::new(MessageDigest::sha1(), &keypair).unwrap();
+ // signer.update(data.as_bytes());
+ // let signature = signer.sign_to_vec();
+
+ println!("{:?}", String::from_utf8_lossy(&signature));
String::new()
}