-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ca certs api v2 #4635
Ca certs api v2 #4635
Conversation
This replicate the current behaviour imeplemented in /ca/rest/certs/<id>.
Implement the REST operations: - GET of /ca/v2/certs - POST to /ca/v2/certs/search. These implement the behaviour of the current REST operations (see [1, 2]). The new version is not based on RESTeasy framework for the REST operation and the DB searches have replaced VLV with paged queries. The only differences with the previous implementation are: - the total value now show the number of returned item; - the number of returned entry is limited (this is hard-coded for now). 1. https://github.com/dogtagpki/pki/wiki/CA-List-Certificates-REST-API 2. https://github.com/dogtagpki/pki/wiki/CA-Search-Certificates-REST-API
@edewata The total can be fixed to provide the exact number if needed but has to be retrieved from the first query and reported to the servlet so it will require some changes. Is this needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments/questions, but I think overall it's good. Feel free to update or merge as is, then we can address the comments in a new PR.
* {@Code (&(certRecordId=5)(x509Cert.notBefore=934398398))} | ||
* | ||
* @param filter search filter | ||
* @param maxSize max size to return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @param
should match the actual method params.
* @return a list of certificates | ||
* @exception EBaseException failed to search | ||
*/ | ||
public Iterator<CertRecord> searchCertificates(String filter, int timeLimit, int start, int size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timeLimit
doesn't seem to be used. Should we keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is implemented in the pagedSeearch. I will add to the call.
String base64 = CertUtil.toPEM(cert); | ||
certData.setEncoded(base64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably an opportunity to fix APIv1. Here we could just return the base64-encoded value without the PEM header/footer. I think that would be easier to parse and more consistent with other binary data in JSON in general. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know in other places yet but here we have the chain in base64 the certificate in pem. It is better to have all base64.
CertPrettyPrint print = new CertPrettyPrint(cert); | ||
certData.setPrettyPrint(print.toString(loc)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pretty-print probably should be generated on the client side because the client already has the cert binaries, and the output would be dependent on client's locale anyway, so I think we can skip this field.
Date notBefore = cert.getNotBefore(); | ||
if (notBefore != null) certData.setNotBefore(notBefore.toString()); | ||
|
||
Date notAfter = cert.getNotAfter(); | ||
if (notAfter != null) certData.setNotAfter(notAfter.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notBefore
and notAfter
probably should be generated on the client side too since it's dependent on client's locale and the client already has the cert binaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave this for the moment. PrettyPrint is better in the client but the validity could be useful without the need to read the binary. What we could change is the format to be more platform independent (e.g. yyyy-MM-dd HH:mm:ss Z). The client can read or generate from binary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we have two different format of data, in the certificate list we have time in milliseconds while in a single certificate we have the string. This because the list uses the class CertDataInfo
while the single certificate uses the class CertData
. These classes are in the same package and have almost the same fields but with different format (e.g. date is Date
in one and String
in the other) . Not clear why we need to have both. We could merge them. To investigate in a separate PR
|
||
int total = results.size(); | ||
logger.info("Search results: " + total); | ||
infos.setTotal(total); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably can skip the total
since it can be obtained from infos.getEntries().size()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is OK to remove for now. The pageSearch
could provide the total number of entries in the DB but the information is not returned from the LDAPSession. If needed we could handle that information to the client. We will consider this in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done a couple of test and it is not enough to skip the setTotal()
, it is reported as total=0
in the final json. I am leaving for now and evaluate in separate PR.
|
||
LDAPSearchConstraints cons = new LDAPSearchConstraints(); | ||
if (timeLimit > 0) { | ||
cons.setServerTimeLimit(timeLimit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LDAPSearchConstraints
also has a setMaxResults()
. I was wondering whether we should just ignore it, set it to size
, or add another param for it (e.g. sizeLimit
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another consideration is, IIUC the size
is only used internally for paging, but the number of results the client will see won't actually be affected by the size
. On the other hand, the sizeLimit
will (if it's used to call setMaxResults()
).
So maybe we should replace size
with a constant or a server-side configurable param, and add a sizeLimit
not for paging but for setting the max results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, size
elements are returned from the search. The size is always used in the last query and the elements are returned . If start is provided, than one or more pages are requested until start - 1
elements are retrieved and then a page with size
is requested.
If size
is not provided there is a limit to 500. I am leaving the limit now and we can decide if this has to be customisable in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the MaxResults. We could discuss better approach with DS folk.
byte[] p7Bytes = bos.toByteArray(); | ||
|
||
String p7Str = Utils.base64encode(p7Bytes, true); | ||
certData.setPkcs7CertChain(p7Str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we should skip this field since not all clients needs to get the PKCS #7 cert chain, so maybe it can be provided by a different API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this field when the new API is created in a separate PR.
revExts.get(CRLReasonExtension.NAME); | ||
certData.setRevocationReason(ext.getReason().getCode()); | ||
} catch (X509ExtensionException e) { | ||
// nothing to do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's log an error so at least we know if something happens.
Kudos, SonarCloud Quality Gate passed! |
@edewata Thanks! I have update following some of your comments. The remaining comments need additional work in separate PRs. |
Implement v2 REST end-point for /ca/v2/certs
Implement the REST operations:
These implement the behaviour of the current REST operations (see [1, 2 and 3]). The new version is not based on RESTeasy framework for the REST operation and the DB searches have replaced VLV with paged queries.
The only differences with the previous implementation are: