Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage help: ecdsa parameters #8

Closed
focusaurus opened this issue Jan 8, 2018 · 1 comment
Closed

Usage help: ecdsa parameters #8

focusaurus opened this issue Jan 8, 2018 · 1 comment

Comments

@focusaurus
Copy link
Contributor

I wonder if you can help me parse the last 2 fields in an ecdsa ssh private key. I have working code to handle the sequence, integer, and octet string, but the final 2 fields I can't figure out how to parse with der-parser. Here's the ASN.1 structure:

ECPrivateKey ::= SEQUENCE {
version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
privateKey OCTET STRING,
parameters [0] ECDomainParameters {{ SECGCurveNames }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL
}

And here's my code, with the first 2 fields of the sequence working but last 2 wrong.

fn der_read_opt_oid(i:&[u8]) -> IResult<&[u8],DerObject,u32> {
    parse_der_optional!(i, parse_der_oid)
}

fn der_read_opt_bitstring(i:&[u8]) -> IResult<&[u8],DerObject,u32> {
    parse_der_optional!(i, parse_der_bitstring)
}

fn parse_oid(i: &[u8]) -> IResult<&[u8], DerObject> {
    parse_der_explicit(i, DerTag::Oid as u8, parse_der_oid)
}

fn parse_bits(i: &[u8]) -> IResult<&[u8], DerObject> {
    parse_der_explicit(i, DerTag::BitString as u8, parse_der_bitstring)
}

fn ecdsa_private(input: &[u8]) -> Algorithm {
    match parse_der_sequence_defined!(
        input,
        parse_der_integer,
        parse_der_octetstring,
        der_read_opt_oid,
        der_read_opt_bitstring,
    ) {
        IResult::Done(_unparsed_suffix, der) => {
            assert_eq!(_unparsed_suffix.len(), 0);
            Algorithm::Ecdsa(0)
        }
        IResult::Error(error) => {
            eprintln!("Error {}", error);
            Algorithm::Unknown
        }
        IResult::Incomplete(_needed) => {
            eprintln!("Incomplete {:?}", _needed);
            Algorithm::Unknown
        }
    }
}
@focusaurus
Copy link
Contributor Author

OK I found another programmer to pair on it and we were able to use der_read_element_content_as based on the examples in the x509 parser and got this working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant