-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-9373] Add SDK support for Certificate API
Added support to be able to query certificates from the fabric CA server. Change-Id: I716c58da4eeb8bee7beeeab7ca5f39e786f32493 Signed-off-by: Saad Karim <skarim@us.ibm.com>
- Loading branch information
Saad Karim
committed
Jun 29, 2018
1 parent
edd54f8
commit f80259c
Showing
10 changed files
with
666 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package org.hyperledger.fabric_ca.sdk; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException; | ||
import org.hyperledger.fabric_ca.sdk.helper.Util; | ||
|
||
/** | ||
* Request to the Fabric CA server to get certificates | ||
* based on filter parameters | ||
*/ | ||
public class HFCACertificateRequest { | ||
|
||
private final Map<String, String> queryParms = new HashMap<>(); | ||
|
||
/** | ||
* Get certificate request from Fabric CA server | ||
*/ | ||
HFCACertificateRequest() { | ||
} | ||
|
||
/** | ||
* Get certificates for this enrollment ID | ||
* | ||
* @param enrollmentID Enrollment ID associated with the certificate(s) | ||
*/ | ||
public void setEnrollmentID(String enrollmentID) { | ||
queryParms.put("id", enrollmentID); | ||
} | ||
|
||
/** | ||
* Get certificates for this serial number | ||
* | ||
* @param serial Serial Number of the certificate | ||
*/ | ||
public void setSerial(String serial) { | ||
queryParms.put("serial", serial); | ||
} | ||
|
||
/** | ||
* Get certificates for this aki | ||
* | ||
* @param aki AKI of the certificate(s) | ||
*/ | ||
public void setAki(String aki) { | ||
queryParms.put("aki", aki); | ||
} | ||
|
||
/** | ||
* Get certificates that have been revoked after this date | ||
* | ||
* @param revokedStart Revoked after date | ||
* @throws InvalidArgumentException Date can't be null | ||
*/ | ||
public void setRevokedStart(Date revokedStart) throws InvalidArgumentException { | ||
if (revokedStart == null) { | ||
throw new InvalidArgumentException("Date can't be null"); | ||
} | ||
queryParms.put("revoked_start", Util.dateToString(revokedStart)); | ||
} | ||
|
||
/** | ||
* Get certificates that have been revoked before this date | ||
* | ||
* @param revokedEnd Revoked before date | ||
* @throws InvalidArgumentException Date can't be null | ||
*/ | ||
public void setRevokedEnd(Date revokedEnd) throws InvalidArgumentException { | ||
if (revokedEnd == null) { | ||
throw new InvalidArgumentException("Date can't be null"); | ||
} | ||
queryParms.put("revoked_end", Util.dateToString(revokedEnd)); | ||
} | ||
|
||
/** | ||
* Get certificates that have expired after this date | ||
* | ||
* @param expiredStart Expired after date | ||
* @throws InvalidArgumentException Date can't be null | ||
*/ | ||
public void setExpiredStart(Date expiredStart) throws InvalidArgumentException { | ||
if (expiredStart == null) { | ||
throw new InvalidArgumentException("Date can't be null"); | ||
} | ||
queryParms.put("expired_start", Util.dateToString(expiredStart)); | ||
} | ||
|
||
/** | ||
* Get certificates that have expired before this date | ||
* | ||
* @param expiredEnd Expired end date | ||
* @throws InvalidArgumentException Date can't be null | ||
*/ | ||
public void setExpiredEnd(Date expiredEnd) throws InvalidArgumentException { | ||
if (expiredEnd == null) { | ||
throw new InvalidArgumentException("Date can't be null"); | ||
} | ||
queryParms.put("expired_end", Util.dateToString(expiredEnd)); | ||
} | ||
|
||
/** | ||
* Get certificates that include/exclude expired certificates | ||
* | ||
* @param expired Boolean indicating if expired certificates should be excluded | ||
*/ | ||
public void setExpired(boolean expired) { | ||
if (expired) { | ||
queryParms.put("notexpired", "false"); | ||
} else { | ||
queryParms.put("notexpired", "true"); | ||
} | ||
} | ||
|
||
/** | ||
* Get certificates that include/exclude revoked certificates | ||
* | ||
* @param revoked Boolean indicating if revoked certificates should excluded | ||
*/ | ||
public void setRevoked(boolean revoked) { | ||
if (revoked) { | ||
queryParms.put("notrevoked", "false"); | ||
} else { | ||
queryParms.put("notrevoked", "true"); | ||
} | ||
} | ||
|
||
/** | ||
* Get all the filter parameters for this certificate request | ||
* | ||
* @return A map of filters that will be used as query parameters in GET request | ||
*/ | ||
public Map<String, String> getQueryParameters() { | ||
return this.queryParms; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.hyperledger.fabric_ca.sdk; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* The response from a certificate API request, contains the status code of the | ||
* request and certificates that were retrieved | ||
*/ | ||
public class HFCACertificateResponse { | ||
private final int statusCode; | ||
private final Collection<HFCACredential> certs; | ||
|
||
/** | ||
* Contains the response from the server with status code and credentials requested | ||
* | ||
* @param statusCode Status code of the HTTP request | ||
* @param certs The certificates return from the GET request | ||
*/ | ||
HFCACertificateResponse(int statusCode, Collection<HFCACredential> certs) { | ||
this.statusCode = statusCode; | ||
this.certs = certs; | ||
} | ||
|
||
/** | ||
* Returns the status code of the request | ||
* | ||
* @return HTTP status code | ||
*/ | ||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
/** | ||
* Returns the certificates that were retrieved from the GET certificate request | ||
* | ||
* @return Certificates | ||
*/ | ||
public Collection<HFCACredential> getCerts() { | ||
return certs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACredential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.hyperledger.fabric_ca.sdk; | ||
|
||
/** | ||
* Credentials supported by Fabric CA | ||
*/ | ||
public abstract class HFCACredential { | ||
} |
Oops, something went wrong.