WIP: make it possible for users to sign activities
This commit is contained in:
+12
-10
@@ -1,20 +1,19 @@
|
||||
use base64;
|
||||
use diesel::PgConnection;
|
||||
use hex;
|
||||
use chrono::Utc;
|
||||
use openssl::sha::sha256;
|
||||
use serde_json;
|
||||
|
||||
// (Comments are from the Mastodon source code, to remember what to do.)
|
||||
|
||||
pub trait Signer {
|
||||
fn get_key_id(&self) -> String;
|
||||
fn get_key_id(&self, conn: &PgConnection) -> String;
|
||||
|
||||
/// Sign some data with the signer keypair
|
||||
fn sign(&self, to_sign: String) -> String; // Base64.strict_encode64(creator.keypair.sign(OpenSSL::Digest::SHA256.new, to_be_signed))
|
||||
fn sign(&self, to_sign: String) -> Vec<u8>;
|
||||
}
|
||||
|
||||
pub trait Signable {
|
||||
fn sign<T>(&mut self, creator: T) -> &mut Self where T: Signer;
|
||||
fn sign<T>(&mut self, creator: T, conn: &PgConnection) -> &mut Self where T: Signer;
|
||||
|
||||
fn hash(data: String) -> String {
|
||||
let bytes = data.into_bytes();
|
||||
@@ -23,15 +22,18 @@ pub trait Signable {
|
||||
}
|
||||
|
||||
impl Signable for serde_json::Value {
|
||||
fn sign<T>(&mut self, creator: T) -> &mut serde_json::Value where T: Signer {
|
||||
fn sign<T: Signer>(&mut self, creator: T, conn: &PgConnection) -> &mut serde_json::Value {
|
||||
let creation_date = Utc::now().to_rfc3339();
|
||||
let mut options = json!({
|
||||
"type": "RsaSignature2017",
|
||||
"creator": creator.get_key_id(), // [ActivityPub::TagManager.instance.uri_for(creator), '#main-key'].join,
|
||||
"created": Utc::now().to_rfc3339()
|
||||
"creator": creator.get_key_id(conn),
|
||||
"created": creation_date
|
||||
});
|
||||
|
||||
//options_hash = hash(options.without('type', 'id', 'signatureValue').merge('@context' => CONTEXT))
|
||||
let options_hash = Self::hash(String::from(""));
|
||||
let options_hash = Self::hash(json!({
|
||||
"@context": "https://w3id.org/identity/v1",
|
||||
"created": creation_date
|
||||
}).to_string());
|
||||
let document_hash = Self::hash(self.to_string());
|
||||
let to_be_signed = options_hash + &document_hash;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user