Skip to content

Commit

Permalink
custom exponent in crsasha2signer
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvolear committed Jul 15, 2024
1 parent 44f25d9 commit 1b2ef4a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
15 changes: 10 additions & 5 deletions contracts/certificate/signers/CRSASHA2Signer.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {RSA} from "../../utils/RSA.sol";
import {SHA1} from "../../utils/SHA1.sol";

contract CRSASHA2Signer {
contract CRSASHA2Signer is Initializable {
using RSA for bytes;

uint256 public constant E = 65537; // RSA exponent
uint256 public constant X509_KEY_BYTE_LENGTH = 512; // 4096 bits
uint256 public exponent; // RSA exponent

function __CRSASHA2Signer_init(uint256 exponent_) external initializer {
exponent = exponent_;
}

/**
* @notice Verifies ICAO member RSA signature of the X509 certificate SA.
Expand All @@ -23,14 +28,14 @@ contract CRSASHA2Signer {
bytes32 x509SAHash = sha256(x509SignedAttributes_);

bytes memory decrypted_ = icaoMemberSignature_.decrypt(
abi.encodePacked(E),
abi.encodePacked(exponent),
icaoMemberKey_
);

bytes32 decryptedX509SAHash_;

assembly {
decryptedX509SAHash_ := mload(add(decrypted_, X509_KEY_BYTE_LENGTH)) // 480 offset + 32 length
decryptedX509SAHash_ := mload(add(decrypted_, mload(decrypted_))) // load the last 32 bytes
}

return x509SAHash == decryptedX509SAHash_;
Expand Down
4 changes: 2 additions & 2 deletions deploy/10_setup.migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export = async (deployer: Deployer) => {

const registration = await deployer.deployed(Registration2Mock__factory, "Registration Proxy");

const cRsa4096Dispatcher = await deployer.deployed(CRSASHA2Dispatcher__factory, "CRSASHA2Dispatcher 512");
const cRsa2048Dispatcher = await deployer.deployed(CRSASHA2Dispatcher__factory, "CRSASHA2Dispatcher 256");
const cRsa4096Dispatcher = await deployer.deployed(CRSASHA2Dispatcher__factory, "CRSASHA2Dispatcher 65537 512");
const cRsa2048Dispatcher = await deployer.deployed(CRSASHA2Dispatcher__factory, "CRSASHA2Dispatcher 65537 256");

const pRsaSha12688Dispatcher = await deployer.deployed(PRSASHA1Dispatcher__factory, "PRSASHA1Dispatcher 65537");
const pRsaSha126883Dispatcher = await deployer.deployed(PRSASHA1Dispatcher__factory, "PRSASHA1Dispatcher 3");
Expand Down
9 changes: 5 additions & 4 deletions deploy/2_registration.migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {

import { getConfig } from "./config/config";

const deployCRSASHA2Dispatcher = async (deployer: Deployer, keyLength: string, keyPrefix: string) => {
const signer = await deployer.deploy(CRSASHA2Signer__factory, { name: `CRSASHA2Signer ${keyLength}` });
const deployCRSASHA2Dispatcher = async (deployer: Deployer, exponent: string, keyLength: string, keyPrefix: string) => {
const signer = await deployer.deploy(CRSASHA2Signer__factory, { name: `CRSASHA2Signer ${exponent} ${keyLength}` });
const dispatcher = await deployer.deploy(CRSASHA2Dispatcher__factory, { name: `CRSASHA2Dispatcher ${keyLength}` });

await signer.__CRSASHA2Signer_init(exponent);
await dispatcher.__CRSASHA2Dispatcher_init(await signer.getAddress(), keyLength, keyPrefix);
};

Expand Down Expand Up @@ -70,8 +71,8 @@ export = async (deployer: Deployer) => {

await deployPVerifiers(deployer);

await deployCRSASHA2Dispatcher(deployer, "512", "0x0282020100");
await deployCRSASHA2Dispatcher(deployer, "256", "0x0282010100");
await deployCRSASHA2Dispatcher(deployer, "65537", "512", "0x0282020100");
await deployCRSASHA2Dispatcher(deployer, "65537", "256", "0x0282010100");

await deployPRSASHA12688Dispatcher(deployer, "65537");
await deployPRSASHA12688Dispatcher(deployer, "3");
Expand Down
1 change: 1 addition & 0 deletions test/registration/Registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe("Registration", () => {
const rsaSha2Signer = await CRSASHA2Signer.deploy();
cRsaSha2Dispatcher = await CRSASHA2Dispatcher.deploy();

await rsaSha2Signer.__CRSASHA2Signer_init(65537);
await cRsaSha2Dispatcher.__CRSASHA2Dispatcher_init(
await rsaSha2Signer.getAddress(),
512,
Expand Down

0 comments on commit 1b2ef4a

Please sign in to comment.