gluu
公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.xdi.oxauth.model.jws.ECDSASigner クラス
org.xdi.oxauth.model.jws.ECDSASigner の継承関係図
Inheritance graph
org.xdi.oxauth.model.jws.ECDSASigner 連携図
Collaboration graph

公開メンバ関数

 ECDSASigner (SignatureAlgorithm signatureAlgorithm, ECDSAPrivateKey ecdsaPrivateKey)
 
 ECDSASigner (SignatureAlgorithm signatureAlgorithm, ECDSAPublicKey ecdsaPublicKey)
 
 ECDSASigner (SignatureAlgorithm signatureAlgorithm, Certificate certificate)
 
String generateSignature (String signingInput) throws SignatureException
 
boolean validateSignature (String signingInput, String signature) throws SignatureException
 
SignatureAlgorithm getSignatureAlgorithm ()
 
Jwt sign (Jwt jwt) throws InvalidJwtException, SignatureException
 
boolean validate (Jwt jwt)
 
boolean validateAuthorizationCode (String authorizationCode, Jwt idToken)
 
boolean validateAccessToken (String accessToken, Jwt idToken)
 

非公開変数類

ECDSAPrivateKey ecdsaPrivateKey
 
ECDSAPublicKey ecdsaPublicKey
 

詳解

著者
Javier Rojas Blum
バージョン
July 31, 2016

構築子と解体子

◆ ECDSASigner() [1/3]

org.xdi.oxauth.model.jws.ECDSASigner.ECDSASigner ( SignatureAlgorithm  signatureAlgorithm,
ECDSAPrivateKey  ecdsaPrivateKey 
)
inline
44  {
45  super(signatureAlgorithm);
47  }
ECDSAPrivateKey ecdsaPrivateKey
Definition: ECDSASigner.java:41
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30

◆ ECDSASigner() [2/3]

org.xdi.oxauth.model.jws.ECDSASigner.ECDSASigner ( SignatureAlgorithm  signatureAlgorithm,
ECDSAPublicKey  ecdsaPublicKey 
)
inline
49  {
50  super(signatureAlgorithm);
52  }
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30
ECDSAPublicKey ecdsaPublicKey
Definition: ECDSASigner.java:42

◆ ECDSASigner() [3/3]

org.xdi.oxauth.model.jws.ECDSASigner.ECDSASigner ( SignatureAlgorithm  signatureAlgorithm,
Certificate  certificate 
)
inline
54  {
55  super(signatureAlgorithm);
56  this.ecdsaPublicKey = certificate.getEcdsaPublicKey();
57  }
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30
ECDSAPublicKey ecdsaPublicKey
Definition: ECDSASigner.java:42

関数詳解

◆ generateSignature()

String org.xdi.oxauth.model.jws.ECDSASigner.generateSignature ( String  signingInput) throws SignatureException
inline
60  {
61  if (getSignatureAlgorithm() == null) {
62  throw new SignatureException("The signature algorithm is null");
63  }
64  if (ecdsaPrivateKey == null) {
65  throw new SignatureException("The ECDSA private key is null");
66  }
67  if (signingInput == null) {
68  throw new SignatureException("The signing input is null");
69  }
70 
71  try {
72  ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(getSignatureAlgorithm().getCurve().getName());
73  ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(ecdsaPrivateKey.getD(), ecSpec);
74 
75  KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "BC");
76  PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
77 
78  Signature signature = Signature.getInstance(getSignatureAlgorithm().getAlgorithm(), "BC");
79  signature.initSign(privateKey);
80  signature.update(signingInput.getBytes(Util.UTF8_STRING_ENCODING));
81 
82  return Base64Util.base64urlencode(signature.sign());
83  } catch (InvalidKeySpecException e) {
84  throw new SignatureException(e);
85  } catch (InvalidKeyException e) {
86  throw new SignatureException(e);
87  } catch (NoSuchAlgorithmException e) {
88  throw new SignatureException(e);
89  } catch (NoSuchProviderException e) {
90  throw new SignatureException(e);
91  } catch (UnsupportedEncodingException e) {
92  throw new SignatureException(e);
93  } catch (Exception e) {
94  throw new SignatureException(e);
95  }
96  }
ECDSAPrivateKey ecdsaPrivateKey
Definition: ECDSASigner.java:41
BigInteger getD()
Definition: ECDSAPrivateKey.java:37
SignatureAlgorithm getSignatureAlgorithm()
Definition: AbstractJwsSigner.java:37

◆ getSignatureAlgorithm()

SignatureAlgorithm org.xdi.oxauth.model.jws.AbstractJwsSigner.getSignatureAlgorithm ( )
inlineinherited

org.xdi.oxauth.model.jws.JwsSignerを実装しています。

37  {
38  return signatureAlgorithm;
39  }
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30

◆ sign()

Jwt org.xdi.oxauth.model.jws.AbstractJwsSigner.sign ( Jwt  jwt) throws InvalidJwtException, SignatureException
inlineinherited

org.xdi.oxauth.model.jws.JwsSignerを実装しています。

42  {
43  String signature = generateSignature(jwt.getSigningInput());
44  jwt.setEncodedSignature(signature);
45  return jwt;
46  }
abstract String generateSignature(String signingInput)

◆ validate()

boolean org.xdi.oxauth.model.jws.AbstractJwsSigner.validate ( Jwt  jwt)
inlineinherited

org.xdi.oxauth.model.jws.JwsSignerを実装しています。

49  {
50  try {
51  String signingInput = jwt.getSigningInput();
52  String signature = jwt.getEncodedSignature();
53 
54  return validateSignature(signingInput, signature);
55  } catch (InvalidJwtException e) {
56  LOG.error(e.getMessage(), e);
57  return false;
58  } catch (SignatureException e) {
59  LOG.error(e.getMessage(), e);
60  return false;
61  } catch (Exception e) {
62  LOG.error(e.getMessage(), e);
63  return false;
64  }
65  }
abstract boolean validateSignature(String signingInput, String signature)
static final Logger LOG
Definition: AbstractJwsSigner.java:28

◆ validateAccessToken()

boolean org.xdi.oxauth.model.jws.AbstractJwsSigner.validateAccessToken ( String  accessToken,
Jwt  idToken 
)
inlineinherited
71  {
72  return validateHash(accessToken, idToken.getClaims().getClaimAsString(JwtClaimName.ACCESS_TOKEN_HASH));
73  }
boolean validateHash(String tokenCode, String tokenHash)
Definition: AbstractJwsSigner.java:75

◆ validateAuthorizationCode()

boolean org.xdi.oxauth.model.jws.AbstractJwsSigner.validateAuthorizationCode ( String  authorizationCode,
Jwt  idToken 
)
inlineinherited
67  {
68  return validateHash(authorizationCode, idToken.getClaims().getClaimAsString(JwtClaimName.CODE_HASH));
69  }
boolean validateHash(String tokenCode, String tokenHash)
Definition: AbstractJwsSigner.java:75

◆ validateSignature()

boolean org.xdi.oxauth.model.jws.ECDSASigner.validateSignature ( String  signingInput,
String  signature 
) throws SignatureException
inline
99  {
100  if (getSignatureAlgorithm() == null) {
101  throw new SignatureException("The signature algorithm is null");
102  }
103  if (ecdsaPublicKey == null) {
104  throw new SignatureException("The ECDSA public key is null");
105  }
106  if (signingInput == null) {
107  throw new SignatureException("The signing input is null");
108  }
109 
110  String algorithm;
111  String curve;
112  switch (getSignatureAlgorithm()) {
113  case ES256:
114  algorithm = "SHA256WITHECDSA";
115  curve = "P-256";
116  break;
117  case ES384:
118  algorithm = "SHA384WITHECDSA";
119  curve = "P-384";
120  break;
121  case ES512:
122  algorithm = "SHA512WITHECDSA";
123  curve = "P-521";
124  break;
125  default:
126  throw new SignatureException("Unsupported signature algorithm");
127  }
128 
129  try {
130  byte[] sigBytes = Base64Util.base64urldecode(signature);
131  byte[] sigInBytes = signingInput.getBytes(Util.UTF8_STRING_ENCODING);
132 
133  ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
134  BigInteger q = ((ECCurve.AbstractFp) ecSpec.getCurve()).getField().getCharacteristic();
135  ECFieldElement xFieldElement = new ECFieldElement.Fp(q, ecdsaPublicKey.getX());
136  ECFieldElement yFieldElement = new ECFieldElement.Fp(q, ecdsaPublicKey.getY());
137  ECPoint pointQ = new ECPoint.Fp(ecSpec.getCurve(), xFieldElement, yFieldElement);
138  ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(pointQ, ecSpec);
139 
140  KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "BC");
141  PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
142 
143  Signature sig = Signature.getInstance(algorithm, "BC");
144  sig.initVerify(publicKey);
145  sig.update(sigInBytes);
146  return sig.verify(sigBytes);
147  } catch (InvalidKeySpecException e) {
148  throw new SignatureException(e);
149  } catch (InvalidKeyException e) {
150  throw new SignatureException(e);
151  } catch (NoSuchAlgorithmException e) {
152  throw new SignatureException(e);
153  } catch (NoSuchProviderException e) {
154  throw new SignatureException(e);
155  } catch (UnsupportedEncodingException e) {
156  throw new SignatureException(e);
157  } catch (Exception e) {
158  throw new SignatureException(e);
159  }
160  }
BigInteger getX()
Definition: ECDSAPublicKey.java:54
SignatureAlgorithm getSignatureAlgorithm()
Definition: AbstractJwsSigner.java:37
ECDSAPublicKey ecdsaPublicKey
Definition: ECDSASigner.java:42
BigInteger getY()
Definition: ECDSAPublicKey.java:62

メンバ詳解

◆ ecdsaPrivateKey

ECDSAPrivateKey org.xdi.oxauth.model.jws.ECDSASigner.ecdsaPrivateKey
private

◆ ecdsaPublicKey

ECDSAPublicKey org.xdi.oxauth.model.jws.ECDSASigner.ecdsaPublicKey
private

このクラス詳解は次のファイルから抽出されました: