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

公開メンバ関数

 RSASigner (SignatureAlgorithm signatureAlgorithm, RSAPrivateKey rsaPrivateKey)
 
 RSASigner (SignatureAlgorithm signatureAlgorithm, RSAPublicKey rsaPublicKey)
 
 RSASigner (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)
 

非公開変数類

RSAPrivateKey rsaPrivateKey
 
RSAPublicKey rsaPublicKey
 

詳解

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

構築子と解体子

◆ RSASigner() [1/3]

org.xdi.oxauth.model.jws.RSASigner.RSASigner ( SignatureAlgorithm  signatureAlgorithm,
RSAPrivateKey  rsaPrivateKey 
)
inline
40  {
41  super(signatureAlgorithm);
43  }
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30
RSAPrivateKey rsaPrivateKey
Definition: RSASigner.java:37

◆ RSASigner() [2/3]

org.xdi.oxauth.model.jws.RSASigner.RSASigner ( SignatureAlgorithm  signatureAlgorithm,
RSAPublicKey  rsaPublicKey 
)
inline
45  {
46  super(signatureAlgorithm);
48  }
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30
RSAPublicKey rsaPublicKey
Definition: RSASigner.java:38

◆ RSASigner() [3/3]

org.xdi.oxauth.model.jws.RSASigner.RSASigner ( SignatureAlgorithm  signatureAlgorithm,
Certificate  certificate 
)
inline
50  {
51  super(signatureAlgorithm);
52  this.rsaPublicKey = certificate.getRsaPublicKey();
53  }
SignatureAlgorithm signatureAlgorithm
Definition: AbstractJwsSigner.java:30
RSAPublicKey rsaPublicKey
Definition: RSASigner.java:38

関数詳解

◆ generateSignature()

String org.xdi.oxauth.model.jws.RSASigner.generateSignature ( String  signingInput) throws SignatureException
inline
56  {
57  if (getSignatureAlgorithm() == null) {
58  throw new SignatureException("The signature algorithm is null");
59  }
60  if (rsaPrivateKey == null) {
61  throw new SignatureException("The RSA private key is null");
62  }
63  if (signingInput == null) {
64  throw new SignatureException("The signing input is null");
65  }
66 
67  try {
68  RSAPrivateKeySpec rsaPrivateKeySpec = new RSAPrivateKeySpec(
71 
72  KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
73  PrivateKey privateKey = keyFactory.generatePrivate(rsaPrivateKeySpec);
74 
75  Signature signature = Signature.getInstance(getSignatureAlgorithm().getAlgorithm(), "BC");
76  signature.initSign(privateKey);
77  signature.update(signingInput.getBytes(Util.UTF8_STRING_ENCODING));
78 
79  return Base64Util.base64urlencode(signature.sign());
80  } catch (InvalidKeySpecException e) {
81  throw new SignatureException(e);
82  } catch (InvalidKeyException e) {
83  throw new SignatureException(e);
84  } catch (NoSuchAlgorithmException e) {
85  throw new SignatureException(e);
86  } catch (NoSuchProviderException e) {
87  throw new SignatureException(e);
88  } catch (SignatureException e) {
89  throw new SignatureException(e);
90  } catch (UnsupportedEncodingException e) {
91  throw new SignatureException(e);
92  } catch (Exception e) {
93  throw new SignatureException(e);
94  }
95  }
BigInteger getPrivateExponent()
Definition: RSAPrivateKey.java:48
SignatureAlgorithm getSignatureAlgorithm()
Definition: AbstractJwsSigner.java:37
BigInteger getModulus()
Definition: RSAPrivateKey.java:40
RSAPrivateKey rsaPrivateKey
Definition: RSASigner.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.RSASigner.validateSignature ( String  signingInput,
String  signature 
) throws SignatureException
inline
98  {
99  if (getSignatureAlgorithm() == null) {
100  throw new SignatureException("The signature algorithm is null");
101  }
102  if (rsaPublicKey == null) {
103  throw new SignatureException("The RSA public key is null");
104  }
105  if (signingInput == null) {
106  throw new SignatureException("The signing input is null");
107  }
108 
109  String algorithm = null;
110  switch (getSignatureAlgorithm()) {
111  case RS256:
112  algorithm = "SHA-256";
113  break;
114  case RS384:
115  algorithm = "SHA-384";
116  break;
117  case RS512:
118  algorithm = "SHA-512";
119  break;
120  default:
121  throw new SignatureException("Unsupported signature algorithm");
122  }
123 
124  ASN1InputStream aIn = null;
125  try {
126  byte[] sigBytes = Base64Util.base64urldecode(signature);
127  byte[] sigInBytes = signingInput.getBytes(Util.UTF8_STRING_ENCODING);
128 
129  RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(
132 
133  KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
134  PublicKey publicKey = keyFactory.generatePublic(rsaPublicKeySpec);
135 
136  Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
137  cipher.init(Cipher.DECRYPT_MODE, publicKey);
138 
139  byte[] decSig = cipher.doFinal(sigBytes);
140  aIn = new ASN1InputStream(decSig);
141 
142  ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
143 
144  MessageDigest hash = MessageDigest.getInstance(algorithm, "BC");
145  hash.update(sigInBytes);
146 
147  ASN1OctetString sigHash = (ASN1OctetString) seq.getObjectAt(1);
148  return MessageDigest.isEqual(hash.digest(), sigHash.getOctets());
149  } catch (IOException e) {
150  throw new SignatureException(e);
151  } catch (NoSuchAlgorithmException e) {
152  throw new SignatureException(e);
153  } catch (InvalidKeyException e) {
154  throw new SignatureException(e);
155  } catch (InvalidKeySpecException e) {
156  throw new SignatureException(e);
157  } catch (NoSuchPaddingException e) {
158  throw new SignatureException(e);
159  } catch (BadPaddingException e) {
160  throw new SignatureException(e);
161  } catch (NoSuchProviderException e) {
162  throw new SignatureException(e);
163  } catch (IllegalBlockSizeException e) {
164  throw new SignatureException(e);
165  } catch (Exception e) {
166  throw new SignatureException(e);
167  } finally {
168  IOUtils.closeQuietly(aIn);
169  }
170  }
BigInteger getModulus()
Definition: RSAPublicKey.java:43
SignatureAlgorithm getSignatureAlgorithm()
Definition: AbstractJwsSigner.java:37
RSAPublicKey rsaPublicKey
Definition: RSASigner.java:38
BigInteger getPublicExponent()
Definition: RSAPublicKey.java:51

メンバ詳解

◆ rsaPrivateKey

RSAPrivateKey org.xdi.oxauth.model.jws.RSASigner.rsaPrivateKey
private

◆ rsaPublicKey

RSAPublicKey org.xdi.oxauth.model.jws.RSASigner.rsaPublicKey
private

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