Also, can you clarify if you're using any existing libraries, and if not why not (just as an academic exercise, or in an attempt to solve some problem the existing libraries don't, or something else?)
I would have expected more options to already exist, but the ACME Client List does point out one existing library that might be helpful, called acme4j.
Once the client believes it has fulfilled the server's requirements,
it should send a POST request to the order resource's finalize URL.
The POST body MUST include a CSR:
csr (required, string): A CSR encoding the parameters for the
certificate being requested [RFC2986]. The CSR is sent in the
base64url-encoded version of the DER format. (Note: Because this
field uses base64url, and does not include headers, it is
different from PEM.)
The CSR encodes the client's requests with regard to the content of
the certificate to be issued. The CSR MUST indicate the exact same
set of requested identifiers as the initial newOrder request.
Identifiers of type "dns" MUST appear either in the commonName
portion of the requested subject name or in an extensionRequest
attribute [RFC2985] requesting a subjectAltName extension, or both.
(These identifiers may appear in any sort order.) Specifications
that define new identifier types must specify where in the
certificate signing request these identifiers can appear.
That said, I have no clue what so ever how that would be working in Java.
I try to generate the csr with openssl but that doesn't work too :
"{ "type": "urn:ietf:params:acme:error:malformed", "detail": "Error unmarshaling finalize order request", "status": 400}"
The commande OPENSSL :
C:\Users\Mascret\IdeaProjects\devops>openssl req -new -key private.key -out request.csr
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:I-F
Locality Name (eg, city) []:Paris
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Almuminune
Organizational Unit Name (eg, section) []:AlmuminuneDev
Common Name (e.g. server FQDN or YOUR name) []:al-muminune.org
Email Address []:mmascret94@gmail.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
The private.key file is the private key i generate to create the account.
cznQMuv5AvoFHkjOxf759g3xSHNvyrKn-8Sv9Pjf-vM.qoadYk9jHQmUBzwVU6gxtMDKBzf4wOKnCm5NvmiUscw is the token that's i return in my challenge (token+ . + static_part_of_account), should i use it ?
The private key used for the CSR should be the same private key as the public key used for the certificate, not the accounts private key.
The token has nothing to do with the CSR.
You shouldn't use any challenge password. At least, I'm never asked about it. Your CSR should either contain a CommonName with the hostname or use a SAN. The "Organization Name" is irrelevant and should not be the place you put the hostname.
If you truly want to proceed down the path of creating your own ACME client, then you need to treat it like science: change only one thing at a time, and carefully document and share both your inputs and your outputs.
For example, saying that you have tried five different methods of creating a CSR is useful, as it suggests that something other than the CSR itself is the issue here. But what would be more useful is sharing everything: all of the commands that you've used to create CSRs, all of the CSR files that have been created as a result of those commands, all of the code that you've used to try to submit those CSRs to an ACME API, and all of the error messages you've gotten in return. We can't help when all we know is "it didn't work". In order to help, we need to know in excruciating detail exactly what didn't work.
While true, it is worth noting that Let's Encrypt cannot issue a certificate containing any of these fields except for CN. LE only issues Domain Validated certificates, which cannot contain other Subject attributes, because validation of those other fields cannot be automated.
Please see @aarongable excellent post above, especially the "In order to help, we need to know in excruciating detail exactly what didn't work." part. Just saying "still doesn't change the problem" won't get you anywhere fast.
StringBuilder sb = new StringBuilder("CN=").append(url);
When i do it that mark the same error : 400 Bad Request: "{ "type": "urn:ietf:params:acme:error:malformed", "detail": "Error parsing certificate request: asn1: syntax error: sequence truncated", "status": 400}"
@Osiris I use the api of LE and i just want to finish an order which i succed and after it download the certificat, so i need to generate a valide array of char (string) that's can be sended to the api.
I tried to generate by many way like PKCS10CertificationRequest / openssl / ... but that still doesnt work (the csr part of the api)
That all was already mentioned in this thread. What is lacking however is "working" (i.e.: compiling/running) pieces of code, complete logs and/or complete send CSRs et cetera.
I'm using the api, i just need to know what i need to put in the csr field.
The error of LE api is 400 Bad Request: "{ "type": "urn:ietf:params:acme:error:malformed", "detail": "Error parsing certificate request: asn1: syntax error: sequence truncated", "status": 400}"
I'm coding from craft so you don't need my global code.
I just need help to understand how to create the csr field.
Like i said either package advice of openssl work.
So the problem may come to the api at this stage.