Skip to content

Commit a04cf05

Browse files
authored
Merge pull request #7 from approov/feature/3.5.3
Feature/3.5.3
2 parents 3e0896d + c09cf21 commit a04cf05

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

.maven/maven-publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ curl --request POST \
2929
--verbose \
3030
--header "Authorization: Bearer ${MAVEN_CREDENTIALS}" \
3131
--form "bundle=@${BODY_ARTIFACT}" \
32-
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=USER_MANAGED&name=service.httpsurlconn"
32+
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC&name=service.httpsurlconn"

approov-service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>io.approov</groupId>
4242
<artifactId>approov-android-sdk</artifactId>
43-
<version>3.5.1</version>
43+
<version>3.5.3</version>
4444
<scope>runtime</scope>
4545
</dependency>
4646
</dependencies>

approov-service/src/main/java/io/approov/service/httpsurlconn/ApproovService.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,74 @@ else if (approovResults.getStatus() != Approov.TokenFetchStatus.SUCCESS)
516516
return approovResults.getToken();
517517
}
518518

519+
/**
520+
* Gets the last ARC (Attestation Response Code) code.
521+
*
522+
* Always resolves with a string (ARC or empty string).
523+
* NOTE: You MUST only call this method upon succesfull attestation completion. Any networking
524+
* errors returned from the service layer will not return a meaningful ARC code if the method is called!!!
525+
* @return String ARC from last attestation request or empty string if network unavailable
526+
*/
527+
public static String getLastARC() {
528+
// Get the dynamic pins from Approov
529+
Map<String, List<String>> approovPins = Approov.getPins("public-key-sha256");
530+
if (approovPins == null || approovPins.isEmpty()) {
531+
Log.e(TAG, "ApproovService: no host pinning information available");
532+
return "";
533+
}
534+
// The approovPins contains a map of hostnames to pin strings. Skip '*' and use another hostname if available.
535+
String hostname = null;
536+
for (String key : approovPins.keySet()) {
537+
if (!"*".equals(key)) {
538+
hostname = key;
539+
break;
540+
}
541+
}
542+
if (hostname != null) {
543+
try {
544+
Approov.TokenFetchResult result = Approov.fetchApproovTokenAndWait(hostname);
545+
if (result.getToken() != null && !result.getToken().isEmpty()) {
546+
String arc = result.getARC();
547+
if (arc != null) {
548+
return arc;
549+
}
550+
}
551+
Log.i(TAG, "ApproovService: ARC code unavailable");
552+
return "";
553+
} catch (Exception e) {
554+
Log.e(TAG, "ApproovService: error fetching ARC", e);
555+
return "";
556+
}
557+
} else {
558+
Log.i(TAG, "ApproovService: ARC code unavailable");
559+
return "";
560+
}
561+
}
562+
563+
/**
564+
* Sets an install attributes token to be sent to the server and associated with this particular
565+
* app installation for future Approov token fetches. The token must be signed, within its
566+
* expiry time and bound to the correct device ID for it to be accepted by the server.
567+
* Calling this method ensures that the next call to fetch an Approov
568+
* token will not use a cached version, so that this information can be transmitted to the server.
569+
*
570+
* @param attrs is the signed JWT holding the new install attributes
571+
* @return void
572+
* @throws ApproovException if the attrs parameter is invalid or the SDK is not initialized
573+
*/
574+
public static void setInstallAttrsInToken(String attrs) throws ApproovException {
575+
try {
576+
Approov.setInstallAttrsInToken(attrs);
577+
Log.d(TAG, "setInstallAttrsInToken");
578+
} catch (IllegalArgumentException e) {
579+
Log.e(TAG, "setInstallAttrsInToken failed with IllegalArgument: " + e.getMessage());
580+
throw new ApproovException("setInstallAttrsInToken: " + e.getMessage());
581+
} catch (IllegalStateException e) {
582+
Log.e(TAG, "setInstallAttrsInToken failed with IllegalState: " + e.getMessage());
583+
throw new ApproovException("setInstallAttrsInToken: " + e.getMessage());
584+
}
585+
}
586+
519587
/**
520588
* Adds Approov to the given connection. The Approov token is added in a header and this
521589
* also overrides the HostnameVerifier with something that pins the connections. If a

0 commit comments

Comments
 (0)