@pagopa/io-react-native-jwt 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ Provides much greater performance for decoding, signing and verifying JWTs!
5
5
 
6
6
  🚀 Use only native functions via the following libraries:
7
7
 
8
- - 🤖 [nimbus-jose-jwt](https://github.com/felx/nimbus-jose-jwt/) on Android
8
+ - 🤖 [nimbus-jose-jwt](https://bitbucket.org/connect2id/nimbus-jose-jwt) on Android
9
9
  - 📱 [JOSESwift](https://github.com/airsidemobile/JOSESwift/) on iOS
10
10
 
11
11
  ## Installation
@@ -83,7 +83,7 @@ dependencies {
83
83
  //noinspection GradleDynamicVersion
84
84
  implementation "com.facebook.react:react-native:+"
85
85
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
86
- implementation 'com.nimbusds:nimbus-jose-jwt:8.0'
86
+ implementation 'com.nimbusds:nimbus-jose-jwt:9.30.2'
87
87
  implementation 'org.bouncycastle:bcprov-jdk15on:[1.56,)'
88
88
 
89
89
  }
@@ -7,9 +7,11 @@ import com.facebook.react.bridge.ReactApplicationContext
7
7
  import com.facebook.react.bridge.ReactContextBaseJavaModule
8
8
  import com.facebook.react.bridge.ReactMethod
9
9
  import com.facebook.react.bridge.ReadableMap
10
+ import com.nimbusds.jose.JOSEObject
10
11
  import com.nimbusds.jose.JWEEncrypter
11
12
  import com.nimbusds.jose.JWEHeader
12
13
  import com.nimbusds.jose.JWEObject
14
+ import com.nimbusds.jose.JWSHeader
13
15
  import com.nimbusds.jose.Payload
14
16
  import com.nimbusds.jose.crypto.ECDSAVerifier
15
17
  import com.nimbusds.jose.crypto.RSAEncrypter
@@ -18,9 +20,11 @@ import com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton
18
20
  import com.nimbusds.jose.crypto.impl.ECDSA.transcodeSignatureToConcat
19
21
  import com.nimbusds.jose.jwk.ECKey
20
22
  import com.nimbusds.jose.jwk.RSAKey
21
- import com.nimbusds.jwt.SignedJWT
23
+ import com.nimbusds.jose.util.JSONObjectUtils
24
+ import com.nimbusds.jose.util.StandardCharset
22
25
  import org.json.JSONObject
23
26
  import java.security.MessageDigest
27
+ import java.text.ParseException
24
28
 
25
29
 
26
30
  class IoReactNativeJwtModule(reactContext: ReactApplicationContext) :
@@ -37,7 +41,21 @@ class IoReactNativeJwtModule(reactContext: ReactApplicationContext) :
37
41
  @ReactMethod
38
42
  fun verify(token: String, jwk: ReadableMap, promise: Promise) {
39
43
  try {
40
- val signedJWT = SignedJWT.parse(token)
44
+
45
+ val parts = JOSEObject.split(token)
46
+ if (parts.size != 3) {
47
+ throw ParseException("Unexpected number of Base64URL parts, must be three", 0)
48
+ }
49
+
50
+ val headerString = parts[0]
51
+ val headerJson = JSONObjectUtils.parse(headerString.decodeToString(), -1);
52
+ val header = JWSHeader.parse(headerJson, headerString);
53
+
54
+ val payload = Payload(parts[1])
55
+ val signature = parts[2]
56
+
57
+ var signingInput = header.toBase64URL().toString() + '.' + payload.toBase64URL().toString();
58
+ val signingInputByteArray = signingInput.toByteArray(StandardCharset.UTF_8)
41
59
  val jwkJson = JSONObject(jwk.toHashMap())
42
60
  var isValid = false
43
61
 
@@ -45,12 +63,12 @@ class IoReactNativeJwtModule(reactContext: ReactApplicationContext) :
45
63
  val internalJwk = ECKey.parse(jwkJson.toString())
46
64
  val verifier = ECDSAVerifier(internalJwk)
47
65
  verifier.jcaContext.provider = BouncyCastleProviderSingleton.getInstance()
48
- isValid = signedJWT.verify(verifier)
66
+ isValid = verifier.verify(header, signingInputByteArray, signature);
49
67
  } else {
50
68
  val internalJwk = RSAKey.parse(jwkJson.toString())
51
69
  val verifier = RSASSAVerifier(internalJwk)
52
70
  verifier.jcaContext.provider = BouncyCastleProviderSingleton.getInstance()
53
- isValid = signedJWT.verify(verifier)
71
+ isValid = verifier.verify(header, signingInputByteArray, signature);
54
72
  }
55
73
  promise.resolve(isValid)
56
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-jwt",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Native support for JWT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -71,7 +71,7 @@
71
71
  "pod-install": "^0.1.0",
72
72
  "prettier": "^2.0.5",
73
73
  "react": "18.2.0",
74
- "react-native": "0.72.1",
74
+ "react-native": "0.72.12",
75
75
  "react-native-builder-bob": "^0.20.0",
76
76
  "release-it": "^15.0.0",
77
77
  "turbo": "^1.10.7",
@@ -90,7 +90,7 @@
90
90
  "engines": {
91
91
  "node": ">= 16.0.0"
92
92
  },
93
- "packageManager": "^yarn@1.22.15",
93
+ "packageManager": "yarn@1.22.19",
94
94
  "jest": {
95
95
  "preset": "react-native",
96
96
  "modulePathIgnorePatterns": [
@@ -166,6 +166,6 @@
166
166
  },
167
167
  "dependencies": {
168
168
  "abab": "^2.0.6",
169
- "zod": "^3.21.4"
169
+ "zod": "^3.22.4"
170
170
  }
171
171
  }