Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastcrypto-zkp/src/bn254/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn get_oidc_url(
OIDCProvider::Credenza3 => format!("https://accounts.credenza3.com/oauth2/authorize?client_id={}&response_type=token&scope=openid+profile+email+phone&redirect_uri={}&nonce={}&state=state", client_id, redirect_url, nonce),
OIDCProvider::Onefc => format!("https://login.onepassport.onefc.com/de3ee5c1-5644-4113-922d-e8336569a462/b2c_1a_prod_signupsignin_onesuizklogin/oauth2/v2.0/authorize?client_id={}&scope=openid&response_type=id_token&redirect_uri={}&nonce={}", client_id, redirect_url, nonce),
OIDCProvider::Arden => format!("https://api.arden.cc/auth/authorize?client_id={}&scope=openid&response_type=id_token&redirect_uri={}&nonce={}", client_id, redirect_url, nonce),

OIDCProvider::BenPay => format!("https://accounts.zkoauth.com?client_id={}&redirect_uri={}&nonce={}", client_id, redirect_url, nonce),
OIDCProvider::AwsTenant((region, tenant_id)) => format!("https://{}.auth.{}.amazoncognito.com/login?response_type=token&client_id={}&redirect_uri={}&nonce={}", tenant_id, region, client_id, redirect_url, nonce),
// this URL is only useful if CLI testing from Sui is needed, can ignore if a frontend test plan is in place
_ => return Err(FastCryptoError::InvalidInput)
Expand Down
13 changes: 11 additions & 2 deletions fastcrypto-zkp/src/bn254/zk_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub enum OIDCProvider {
FanTV,
/// https://api.arden.cc/auth/jwks
Arden,
/// https://accounts.zkoauth.com/api/oauth2/jwks https://benpay_oauth.openblock.vip/api/oauth2/jwks
BenPay,
}

impl FromStr for OIDCProvider {
Expand All @@ -144,6 +146,7 @@ impl FromStr for OIDCProvider {
"Onefc" => Ok(Self::Onefc),
"FanTV" => Ok(Self::FanTV),
"Arden" => Ok(Self::Arden),
"BenPay" => Ok(Self::BenPay),
_ => {
let re = Regex::new(
r"AwsTenant-region:(?P<region>[^.]+)-tenant_id:(?P<tenant_id>[^/]+)",
Expand Down Expand Up @@ -181,7 +184,8 @@ impl ToString for OIDCProvider {
Self::Arden => "Arden".to_string(),
Self::AwsTenant((region, tenant_id)) => {
format!("AwsTenant-region:{}-tenant_id:{}", region, tenant_id)
}
},
Self::BenPay => "BenPay".to_string(),
}
}
}
Expand Down Expand Up @@ -256,6 +260,10 @@ impl OIDCProvider {
"https://oidc.arden.cc",
"https://api.arden.cc/auth/jwks",
),
OIDCProvider::BenPay => ProviderConfig::new(
"https://accounts.zkoauth.com",
"https://accounts.zkoauth.com/api/oauth2/jwks"
),
}
}

Expand All @@ -278,6 +286,7 @@ impl OIDCProvider {
}
"https://accounts.fantv.world" => Ok(Self::FanTV),
"https://oidc.arden.cc" => Ok(Self::Arden),
"https://accounts.zkoauth.com" => Ok(Self::BenPay),
iss if match_micrsoft_iss_substring(iss) => Ok(Self::Microsoft),
_ => match parse_aws_iss_substring(iss) {
Ok((region, tenant_id)) => {
Expand Down Expand Up @@ -438,7 +447,7 @@ pub fn fetch_jwk_from_salt_service(

let json_str = String::from_utf8_lossy(&bytes);
let parsed: JWKReader = serde_json::from_str(&json_str)
.map_err(|_| FastCryptoError::GeneralError("Parse error".to_string()))?;
.map_err(|e| FastCryptoError::GeneralError(format!("Parse error {:?}", e.to_string())))?;

Ok(JWK::from_reader(parsed)?)
}
Expand Down
25 changes: 23 additions & 2 deletions fastcrypto/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ use crate::hash::{HashFunction, Sha256};
pub use base64ct::{Base64UrlUnpadded, Encoding};
use rsa::pkcs1::DecodeRsaPublicKey;
use rsa::pkcs1v15::Signature as ExternalSignature;
use rsa::{BigUint, RsaPublicKey as ExternalPublicKey};
use rsa::{Pkcs1v15Sign, PublicKey};
use rsa::{BigUint, RsaPublicKey as ExternalPublicKey, RsaPrivateKey as ExternalPrivateKey};
use rsa::{Pkcs1v15Sign, PublicKey, Oaep};
use rsa::pkcs8::DecodePrivateKey;

#[derive(Clone)]
pub struct RSAPublicKey(pub ExternalPublicKey);

#[derive(Clone, PartialEq, Eq)]
pub struct RSASignature(pub ExternalSignature);

#[derive(Clone)]
pub struct RSAPrivateKey(pub ExternalPrivateKey);

impl RSAPublicKey {
/// Parse an `RSAPublicKey` from an ASN.1 DER (Distinguished Encoding Rules) PKCS #1 encoding.
pub fn from_der(der: &[u8]) -> FastCryptoResult<Self> {
Expand Down Expand Up @@ -63,6 +67,23 @@ impl RSASignature {
}
}

impl RSAPrivateKey {
/// https://datatracker.ietf.org/doc/html/rfc5208
pub fn from_pkcs8_der_bytes(bytes: &[u8]) -> FastCryptoResult<Self> {
Ok(Self(ExternalPrivateKey::from_pkcs8_der(bytes).map_err(|_| FastCryptoError::InvalidInput)?))
}

pub fn from_pkcs8_pem_str(pkcs8_pem: &str) -> FastCryptoResult<Self> {
Ok(Self(ExternalPrivateKey::from_pkcs8_pem(pkcs8_pem).map_err(|_| FastCryptoError::InvalidInput)?))
}

pub fn decrypt_with_oaep_sha256(&self, bytes: &[u8]) -> FastCryptoResult<String> {
let decrypted_bytes = ExternalPrivateKey::decrypt(&self.0, Oaep::new::<sha2::Sha256>(), bytes).map_err(|_| FastCryptoError::InvalidInput)?;
let decrypted_str = String::from_utf8(decrypted_bytes).map_err(|_| FastCryptoError::InvalidInput)?;
Ok(decrypted_str)
}
}

#[cfg(test)]
mod test {
use crate::hash::{HashFunction, Sha256};
Expand Down