diff --git a/.idea/compiler.xml b/.idea/compiler.xml index bbc7654..9eedf16 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -14,7 +14,7 @@ \ No newline at end of file diff --git a/server/build.gradle b/server/build.gradle index d8ddad1..04abd31 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -6,7 +6,8 @@ plugins { group = 'com.yogit' version = '0.0.1-SNAPSHOT' -sourceCompatibility = '11' +sourceCompatibility = '17' +targetCompatibility = '17' configurations { compileOnly { @@ -41,5 +42,5 @@ tasks.named('test') { compileJava.options.compilerArgs.addAll([ "--add-exports=java.base/sun.security.pkcs=ALL-UNNAMED", "--add-exports=java.base/sun.security.util=ALL-UNNAMED", - "--add-exports=java.base/sun.security.x509=ALL-UNNAMED", + "--add-exports=java.base/sun.security.x509=ALL-UNNAMED" ]) diff --git a/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java b/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java index 396f4c8..8afa0de 100644 --- a/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java +++ b/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java @@ -11,6 +11,7 @@ import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; +import java.security.NoSuchAlgorithmException; import java.util.Map; @Controller @@ -68,7 +69,7 @@ public String appleLogin(ModelMap model) { */ @PostMapping(value = "/redirect") @ResponseBody - public TokenResponse servicesRedirect(ServicesResponse serviceResponse) { + public TokenResponse servicesRedirect(ServicesResponse serviceResponse) throws NoSuchAlgorithmException { System.out.println("1------------"); diff --git a/server/src/main/java/com/yogit/server/applelogin/service/AppleService.java b/server/src/main/java/com/yogit/server/applelogin/service/AppleService.java index cf06cc1..078847f 100644 --- a/server/src/main/java/com/yogit/server/applelogin/service/AppleService.java +++ b/server/src/main/java/com/yogit/server/applelogin/service/AppleService.java @@ -2,11 +2,12 @@ import com.yogit.server.applelogin.model.TokenResponse; +import java.security.NoSuchAlgorithmException; import java.util.Map; public interface AppleService { - String getAppleClientSecret(String id_token); + String getAppleClientSecret(String id_token) throws NoSuchAlgorithmException; TokenResponse requestCodeValidations(String client_secret, String code, String refresh_token); diff --git a/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java b/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java index 95a4c5b..6cdd73f 100644 --- a/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java +++ b/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.security.NoSuchAlgorithmException; import java.util.Map; @Service @@ -20,7 +21,7 @@ public class AppleServiceImpl implements AppleService { * @return */ @Override - public String getAppleClientSecret(String id_token) { + public String getAppleClientSecret(String id_token) throws NoSuchAlgorithmException { if (appleUtils.verifyIdentityToken(id_token)) { return appleUtils.createClientSecret(); diff --git a/server/src/main/java/com/yogit/server/applelogin/util/AppleUtils.java b/server/src/main/java/com/yogit/server/applelogin/util/AppleUtils.java index f325591..5f38dd9 100644 --- a/server/src/main/java/com/yogit/server/applelogin/util/AppleUtils.java +++ b/server/src/main/java/com/yogit/server/applelogin/util/AppleUtils.java @@ -22,9 +22,12 @@ import java.io.FileReader; import java.io.IOException; -import java.security.InvalidKeyException; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; import java.text.ParseException; import java.util.Date; import java.util.HashMap; @@ -126,7 +129,7 @@ private boolean verifyPublicKey(SignedJWT signedJWT) { * * @return client_secret(jwt) */ - public String createClientSecret() { + public String createClientSecret() throws NoSuchAlgorithmException { JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.ES256).keyID(KEY_ID).build(); JWTClaimsSet claimsSet = new JWTClaimsSet(); @@ -140,16 +143,28 @@ public String createClientSecret() { SignedJWT jwt = new SignedJWT(header, claimsSet); +// try { +// ECPrivateKey ecPrivateKey = new ECPrivateKeyImpl2(readPrivateKey()); +// JWSSigner jwsSigner = new ECDSASigner(ecPrivateKey.getS()); +// +// jwt.sign(jwsSigner); +// +// } catch (InvalidKeyException e) { +// e.printStackTrace(); +// } catch (JOSEException e) { +// e.printStackTrace(); +// } + + PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(readPrivateKey()); + KeyFactory kf = KeyFactory.getInstance("EC"); try { - ECPrivateKey ecPrivateKey = new ECPrivateKeyImpl2(readPrivateKey()); + ECPrivateKey ecPrivateKey = (ECPrivateKey) kf.generatePrivate(spec); JWSSigner jwsSigner = new ECDSASigner(ecPrivateKey.getS()); - jwt.sign(jwsSigner); - - } catch (InvalidKeyException e) { - e.printStackTrace(); } catch (JOSEException e) { e.printStackTrace(); + } catch (InvalidKeySpecException e) { + throw new RuntimeException(e); } return jwt.serialize(); diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index d616f2f..64a5548 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -12,4 +12,4 @@ spring: jpa: database: mysql hibernate: - ddl-auto: create \ No newline at end of file + ddl-auto: update \ No newline at end of file