cloudflare/boring

boring seems incompatible with rsa crate

dvc94ch opened this issue · 0 comments

assuming that the error is in boringssl as I've used the rsa crate in the past with "other" rsa implementations. the android debug bridge protocol uses boringssl which fails to validate rsa signatures. used boring to try to reproduce.

    #[test]
    fn test_sign() {
        let token = [0; 20];
        let private_key = RsaPrivateKey::new(&mut rand::rngs::OsRng, 2048).unwrap();
        let padding = PaddingScheme::new_pkcs1v15_sign(Some(Hash::SHA1));
        let signature = private_key.sign(padding, &token).unwrap();
        use rsa::pkcs8::EncodePublicKey;
        use rsa::pkcs1::der::Document;
        let public_key = RsaPublicKey::from(&private_key);
        //let public_key = public_key.to_public_key_pem(rsa::pkcs1::LineEnding::LF).unwrap();
        let public_key = public_key.to_public_key_der().unwrap();
        let public_key = public_key.as_der();
        unsafe {
            let public_key = boring_sys::RSA_public_key_from_bytes(public_key.as_ptr(), public_key.len());
            if public_key.is_null() {
                for err in boring::error::ErrorStack::get().errors() {
                    println!("{}", err);
                }
                panic!();
            }
            let res = boring_sys::RSA_verify(
                boring_sys::NID_sha1,
                token.as_ptr(),
                token.len(),
                signature.as_ptr(),
                signature.len(),
                public_key,
            );
            if res != 1 {
                for err in boring::error::ErrorStack::get().errors() {
                    println!("{}", err);
                }
                panic!();
            }
        };
    }
BAD_ENCODING

Code: 03000075
Loc: /home/dvc/.cargo/registry/src/github.com-1ecc6299db9ec823/boring-sys-2.0.0/deps/boringssl/src/crypto/bn_extra/bn_asn1.c:26
BAD_ENCODING

Code: 04000064
Loc: /home/dvc/.cargo/registry/src/github.com-1ecc6299db9ec823/boring-sys-2.0.0/deps/boringssl/src/crypto/rsa_extra/rsa_asn1.c:100
BAD_ENCODING

Code: 04000064
Loc: /home/dvc/.cargo/registry/src/github.com-1ecc6299db9ec823/boring-sys-2.0.0/deps/boringssl/src/crypto/rsa_extra/rsa_asn1.c:120
thread 'client::tests::test_sign' panicked at 'explicit panic', adb-rs/src/client.rs:532:1