Skip to content

Commit

Permalink
add JWE algs to selectors
Browse files Browse the repository at this point in the history
closes #18
  • Loading branch information
jricher committed Jan 14, 2021
1 parent 9881bf3 commit f0aa3ac
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 66 deletions.
10 changes: 7 additions & 3 deletions src/main/java/edu/mit/mkjwk/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ public class API {
ImmutableSet<Algorithm> rsaAlgs = ImmutableSet.of(JWSAlgorithm.RS256, JWSAlgorithm.RS384, JWSAlgorithm.RS512,
JWSAlgorithm.PS256, JWSAlgorithm.PS384, JWSAlgorithm.PS512,
JWEAlgorithm.RSA1_5, JWEAlgorithm.RSA_OAEP, JWEAlgorithm.RSA_OAEP_256);
ImmutableSet<JWSAlgorithm> octAlgs = ImmutableSet.of(JWSAlgorithm.HS256, JWSAlgorithm.HS384, JWSAlgorithm.HS512);
ImmutableSet<JWSAlgorithm> ecAlgs = ImmutableSet.of(JWSAlgorithm.ES256, JWSAlgorithm.ES384, JWSAlgorithm.ES512,
JWSAlgorithm.EdDSA, JWSAlgorithm.ES256K);
ImmutableSet<Algorithm> octAlgs = ImmutableSet.of(JWSAlgorithm.HS256, JWSAlgorithm.HS384, JWSAlgorithm.HS512,
JWEAlgorithm.A128KW, JWEAlgorithm.A192KW, JWEAlgorithm.A256KW,
JWEAlgorithm.A128GCMKW, JWEAlgorithm.A192GCMKW, JWEAlgorithm.A256GCMKW,
JWEAlgorithm.DIR);
ImmutableSet<Algorithm> ecAlgs = ImmutableSet.of(JWSAlgorithm.ES256, JWSAlgorithm.ES384, JWSAlgorithm.ES512,
JWSAlgorithm.EdDSA, JWSAlgorithm.ES256K,
JWEAlgorithm.ECDH_ES, JWEAlgorithm.ECDH_ES_A128KW, JWEAlgorithm.ECDH_ES_A192KW, JWEAlgorithm.ECDH_ES_A256KW);

ImmutableSet<Curve> ecCurves = ImmutableSet.of(Curve.P_256, Curve.SECP256K1, Curve.P_384, Curve.P_521);
ImmutableSet<Curve> okpCurves = ImmutableSet.of(Curve.Ed25519, Curve.Ed448, Curve.X25519, Curve.X448);
Expand Down
113 changes: 66 additions & 47 deletions src/main/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,68 @@ class MkJwk extends React.Component {

}

const AlgSelector = ({...props}) => {

const algs = keyToAlg(props.kty, props.use);

const opts = algs.map(a => {
return(
<option key={a} value={a}>{a}: {props.t('key_props.algs.' + a)}</option>
);
});

return(
<Form.Field>
<Form.Label>{props.t('key_props.alg')}</Form.Label>
<Form.Control>
<Form.Select onChange={props.setAlg} value={props.alg || ''} className='is-fullwidth'>
<option value=''></option>
{opts}
</Form.Select>
</Form.Control>
</Form.Field>
);

}

const keyToAlg = (kty, use) => {
if (use) {
if (use === 'sig') {
if (kty === 'rsa') {
return ['RS256','RS384','RS512','PS256','PS384','PS512'];
} else if (kty === 'ec') {
return ['ES256','ES384','ES512','ES256K'];
} else if (kty === 'oct') {
return ['HS256','HS384','HS512'];
} else if (kty === 'okp') {
return ['EdDSA'];
} else {
return [];
}
} else if (use === 'enc') {
if (kty === 'rsa') {
return ['RSA1_5','RSA-OAEP','RSA-OAEP-256'];
} else if (kty === 'ec') {
return ['ECDH-ES','ECDH-ES+A128KW','ECDH-ES+A192KW','ECDH-ES+A256KW'];
} else if (kty === 'oct') {
return ['A128KW','A192KW','A256KW','A128GCMKW','A192GCMKW','A256GCMKW','dir'];
} else if (kty === 'okp') {
return ['ECDH-ES','ECDH-ES+A128KW','ECDH-ES+A192KW','ECDH-ES+A256KW'];
} else {
return [];
}
} else {
return [];
}
} else {
return [
...keyToAlg(kty, 'sig'),
...keyToAlg(kty, 'enc')
];
}
}


const KeyProps = ({...props}) => {
if (props.kty == 'rsa') {
return (
Expand All @@ -172,20 +234,7 @@ const KeyProps = ({...props}) => {
</Form.Field>
</Columns.Column>
<Columns.Column>
<Form.Field>
<Form.Label>{props.t('key_props.alg')}</Form.Label>
<Form.Control>
<Form.Select onChange={props.setAlg} value={props.alg || ''} className='is-fullwidth'>
<option value=''></option>
<option value='RS256'>{props.t('key_props.signing_alg.RS256')}</option>
<option value='RS384'>{props.t('key_props.signing_alg.RS384')}</option>
<option value='RS512'>{props.t('key_props.signing_alg.RS512')}</option>
<option value='PS256'>{props.t('key_props.signing_alg.PS256')}</option>
<option value='PS384'>{props.t('key_props.signing_alg.PS384')}</option>
<option value='PS512'>{props.t('key_props.signing_alg.PS512')}</option>
</Form.Select>
</Form.Control>
</Form.Field>
<AlgSelector setAlg={props.setAlg} alg={props.alg} use={props.use} kty={props.kty} t={props.t} />
</Columns.Column>
<KeyIdSelector gen={props.gen} kid={props.kid} setGen={props.setGen} setKid={props.setKid} t={props.t} />
<Columns.Column>
Expand Down Expand Up @@ -234,19 +283,7 @@ const KeyProps = ({...props}) => {
</Form.Field>
</Columns.Column>
<Columns.Column>
<Form.Field>
<Form.Label>{props.t('key_props.alg')}</Form.Label>
<Form.Control>
<Form.Select onChange={props.setAlg} value={props.alg || ''} className='is-fullwidth'>
<option value=''></option>
<option value='ES256'>{props.t('key_props.signing_alg.ES256')}</option>
<option value='ES384'>{props.t('key_props.signing_alg.ES384')}</option>
<option value='ES512'>{props.t('key_props.signing_alg.ES512')}</option>
<option value='EdDSA'>{props.t('key_props.signing_alg.EdDSA')}</option>
<option value='ES256K'>{props.t('key_props.signing_alg.ES256K')}</option>
</Form.Select>
</Form.Control>
</Form.Field>
<AlgSelector setAlg={props.setAlg} alg={props.alg} use={props.use} kty={props.kty} t={props.t} />
</Columns.Column>
<KeyIdSelector gen={props.gen} kid={props.kid} setGen={props.setGen} setKid={props.setKid} t={props.t} />
<Columns.Column>
Expand Down Expand Up @@ -289,17 +326,7 @@ const KeyProps = ({...props}) => {
</Form.Field>
</Columns.Column>
<Columns.Column>
<Form.Field>
<Form.Label>{props.t('key_props.alg')}</Form.Label>
<Form.Control>
<Form.Select onChange={props.setAlg} value={props.alg || ''} className='is-fullwidth'>
<option value=''></option>
<option value='HS256'>{props.t('key_props.signing_alg.HS256')}</option>
<option value='HS384'>{props.t('key_props.signing_alg.HS384')}</option>
<option value='HS512'>{props.t('key_props.signing_alg.HS512')}</option>
</Form.Select>
</Form.Control>
</Form.Field>
<AlgSelector setAlg={props.setAlg} alg={props.alg} use={props.use} kty={props.kty} t={props.t} />
</Columns.Column>
<KeyIdSelector gen={props.gen} kid={props.kid} setGen={props.setGen} setKid={props.setKid} t={props.t} />
<Columns.Column>
Expand Down Expand Up @@ -337,15 +364,7 @@ const KeyProps = ({...props}) => {
</Form.Field>
</Columns.Column>
<Columns.Column>
<Form.Field>
<Form.Label>{props.t('key_props.alg')}</Form.Label>
<Form.Control>
<Form.Select onChange={props.setAlg} value={props.alg || ''} className='is-fullwidth'>
<option value=''></option>
<option value='EdDSA'>{props.t('key_props.signing_alg.EdDSA')}</option>
</Form.Select>
</Form.Control>
</Form.Field>
<AlgSelector setAlg={props.setAlg} alg={props.alg} use={props.use} kty={props.kty} t={props.t} />
</Columns.Column>
<KeyIdSelector gen={props.gen} kid={props.kid} setGen={props.setGen} setKid={props.setKid} t={props.t} />
<Columns.Column>
Expand Down
51 changes: 35 additions & 16 deletions src/main/js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,41 @@ const resources = {
kid: 'Key ID',
crv: 'Curve',
make_x509: 'Show X.509',
signing_alg: {
none: 'none',
HS256: 'HS256 (HMAC using SHA-256)',
HS384: 'HS384 (HMAC using SHA-384)',
HS512: 'HS512 (HMAC using SHA-512)',
RS256: 'RS256 (RSASSA-PKCS1-v1_5 using SHA-256)',
RS384: 'RS384 (RSASSA-PKCS1-v1_5 using SHA-384)',
RS512: 'RS512 (RSASSA-PKCS1-v1_5 using SHA-512)',
ES256: 'ES256 (ECDSA using P-256 and SHA-256)',
ES384: 'ES384 (ECDSA using P-384 and SHA-384)',
ES512: 'ES512 (ECDSA using P-521 and SHA-512)',
PS256: 'PS256 (RSASSA-PSS using SHA-256 and MGF1 with SHA-256)',
PS384: 'PS384 (RSASSA-PSS using SHA-384 and MGF1 with SHA-384)',
PS512: 'PS512 (RSASSA-PSS using SHA-512 and MGF1 with SHA-512)',
EdDSA: 'EdDSA',
ES256K: 'ES256K'
algs: {
HS256: 'HMAC using SHA-256',
HS384: 'HMAC using SHA-384',
HS512: 'HMAC using SHA-512',
RS256: 'RSASSA-PKCS1-v1_5 using SHA-256',
RS384: 'RSASSA-PKCS1-v1_5 using SHA-384',
RS512: 'RSASSA-PKCS1-v1_5 using SHA-512',
ES256: 'ECDSA using P-256 and SHA-256',
ES384: 'ECDSA using P-384 and SHA-384',
ES512: 'ECDSA using P-521 and SHA-512',
PS256: 'RSASSA-PSS using SHA-256 and MGF1 with SHA-256',
PS384: 'RSASSA-PSS using SHA-384 and MGF1 with SHA-384',
PS512: 'RSASSA-PSS using SHA-512 and MGF1 with SHA-512',
none: 'No digital signature or MAC performed',
RSA1_5: 'RSAES-PKCS1-v1_5',
'RSA-OAEP': 'RSAES OAEP using default parameters',
'RSA-OAEP-256': 'RSAES OAEP using SHA-256 and MGF1 with SHA-256',
A128KW: 'AES Key Wrap using 128-bit key',
A192KW: 'AES Key Wrap using 192-bit key',
A256KW: 'AES Key Wrap using 256-bit key',
dir: 'Direct use of a shared symmetric key',
'ECDH-ES': 'ECDH-ES using Concat KDF',
'ECDH-ES+A128KW': 'ECDH-ES using Concat KDF and "A128KW" wrapping',
'ECDH-ES+A192KW': 'ECDH-ES using Concat KDF and "A192KW" wrapping',
'ECDH-ES+A256KW': 'ECDH-ES using Concat KDF and "A256KW" wrapping',
A128GCMKW: 'Key wrapping with AES GCM using 128-bit key',
A192GCMKW: 'Key wrapping with AES GCM using 192-bit key',
A256GCMKW: 'Key wrapping with AES GCM using 256-bit key',
'PBES2-HS256+A128KW': 'PBES2 with HMAC SHA-256 and "A128KW" wrapping',
'PBES2-HS384+A192KW': 'PBES2 with HMAC SHA-384 and "A192KW" wrapping',
'PBES2-HS512+A256KW': 'PBES2 with HMAC SHA-512 and "A256KW" wrapping',
EdDSA: 'EdDSA signature algorithms',
'RSA-OAEP-384': 'RSA-OAEP using SHA-384 and MGF1 with SHA-384',
'RSA-OAEP-512': 'RSA-OAEP using SHA-512 and MGF1 with SHA-512',
ES256K: 'ECDSA using secp256k1 curve and SHA-256'
},
ec_crv: {
P256: 'P-256',
Expand Down

0 comments on commit f0aa3ac

Please sign in to comment.