-
Notifications
You must be signed in to change notification settings - Fork 128
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
ber2der #79
Comments
To help analysing the problem I have created a tcpdump: Also, I have tried to understand the offending message |
A small update - we have changed out configuration a bit and were able to test against the SCEP server that we have to target later in the product. In that configuration the certificate enroll works fine with the JSCEP library. |
I also see this problem when using a jscep client and trying to access the micromdm scep server (v 1.0). I can try to produce a log of the http request as received by the scep server - do you have any way of forcing that dump from the scep server itself (enable some logging) or must I capture the raw packets from the network? |
you can edit the code and add a httputil.DumpRequest(true, r) and then write that byte array to disk. |
Not a Go programmer, so ... Would I put this call in the server/transport.go:decodeSCEPRequest function? I also presume I should write its return value to a file (or just pop it onto stdout). Always wanted to learn go - just never had the free time. :-) |
http.log |
Oh and one more thing - when I build from the master source instead of using the 1.0 build via zip, I get a different error. Instead of Invalid BER format, I now see: Perhaps that is a better hint. |
I'll look into the log, thank you. When you are building from source, how are you downloading the dependencies? Make sure you're using |
hmm @bjvetter, I took the request from your http.log and passed it to
Maybe this is not a PKCSReq that is failing but another operation? If you have client side logs that would be useful. |
Note that the |
I followed the README.md instructions: I'll be out the next day, but will take a closer look at versions as well as run the pkcs7.Parse() program/test you posted to see if that works in my environment outside of the scep server. I can try to see if I can enable some client logging, but not sure how easy that will be. |
After some experimenting with your main.go program, it parses the data in the http request correctly. I then switched it to use github.com/groob/pkcs7 instead and I get a "Invalid BER format" error, so there is definitely something different about the two different pkcs7 repos w.r.t. how they operate. Not being experienced with go, I ran "make deps", etc, and tried to replace the older groob/pkcs7 with the newer fullsailor/pkcs7 package, but apparently, there have been changes such that it no longer compiles. I see the following errors: I don't see evidence of functions/fields/arguments with these names. I do see the following in the latest fullsailor and groob repos:
Digging around in the go pkg repo after the make deps, I see the version of scep.go that has a different signature that looks like it supports a collection of options. It was in this repo: So make deps is pulling down a pkcs7 library that is at least compatible. So not sure how one validates "the versions of transitive dependencies correctly" in go, but following the build seems to produce something that will compile. Substituting for the master builds of pkcs7 from fullsailor or groob won't. BUT, I think this is all moot and not the core issue. I hacked the transport code to parse the http message received using the pcs7 and spew it out like you have in your main.go example. It parses the message just fine and spews it all over stdout. Then when it calls the SCEPRequest() function with the same message as input, I get the "BER tag length is more than available data" error. So I don't think the issue is in the pkcs7 handling, but in the the SCEPRequest handler somewhere. |
If you dump the request out after reading it for debugging you cannot pass it along to be read a second time. Reading it zeroes it out. You would have to reconstruct the body again from your byte slice. So your new error messsge might be a red herring. To test this properly delete all your local changes and reinstall the project, but compile the dependencies correctly this time. If it still fails please attach any logs. |
As I already mentioned the head of this project depends on a branch in the groob/pkcs7 repo. The master version of that branch is 3 years old. Using the makefile should result in the correct branch. Using got clone or go get manually to fetch dependencies will fail. |
Just to be clear, I did not use git manually. I did perform the installing/compiling instructions from the readme on your github root dir:
I only attempted to use git directly when I read your response about the old pkcs7 library and statement about "transitive dependencies" thinking I needed to get an updated version. I have blown away all of those "variations" and was adding debug logic to the code that is built as discussed above (got get...; make deps; make build). To recap what I am seeing:
When I add code to parse the request (after the message is retrieved but before calling SCEPRequest with the message), the call to pkcs7.Parse(msg) is successful and it happily "spews" out a dump of the request. It still gets the exact same error "ber2der: BER tag length is more than available data". The code in decodeSCEPRequest() is the following:
I now have another SCEP server to test against (a jscep-based server) and it handles the request without an error. I am happy to help you debug through this issue if you wish, or I can just go away. |
your call to Parse is under a conditional. What if you remove the conditional, is it still always happy? |
If I remove the conditional/debug code, it still fails with the same error. The length being 2770 is the actual SCEPRequest that I care about (the actual CSR). I was using the 2770 length to avoid looking at the getCACaps and other ops that were being issued. If I force it to return "nil" instead of dropping out after the conditional and create/return the SCEPRequest(), I get a whole lot of unhappiness but I do not see the error "ber2der: BER tag length is more than available data". I also wrote out some messages before and after the SCEPRequest call. SCEPRequest seems to not be the source of the error message either. The error happens after we return the request object that was parsed by SCEPRequest. All my debugging/logging so far seems to suggest that the message passed to SCEPRequest is a good CSR - it is parsed properly by the pkcs7 package without an error and its resulting object is "spewable". Now perhaps what is being "spewed" isn't fully happy by whoever is receiving the actual request object. I can capture the "spewed output" and provide that to you if you wish, unless something else to try would be better. |
On impulse, I went into the dependent pkcs7 library (in ber.go) and added a "panic(...)" call when that error is generated. I see the following stack trace if that is at all helpful:
|
Ah I see. Parse is called twice, and we're not looking at DecryptPKIEnvelope, which is where the message is failing. Any chance you could store the Line 309 in 1e0c4b7
|
Interestingly enough, the data being written is only 1000 bytes long (perhaps that is what you expected?) The zip file contains both the original binary data received in the http request and the data that is presented to pkcs7.parse in the scep/scep/scep.go (DecryptPKIEnvelope) |
fwiw asn1parse fails too
|
And yes, i can reproduce with Go. Now the question is, does the go pkcs7 library fail to cut off the data as needed, or is the client encoding it wrong. |
making some progress with the payload. Somehow the full size gets converted to 1000 during a asn1.Unmarshal call. |
So just to be clear, the raw pkcs7 data that is captured in transport.go is 2770 bytes and is happily parsed by openssl - either by openssl pkcs7 or openssl asn1parse. But whatever that 1000 bytes of data is, it doesn't seem parseable by either. I looked at the two files a tad closer, and while they start out looking the same, they diverge around byte #18. So, it is pretty messed up. BTW, the payload seems to work fine with another SCEP server, so either the client/server are using some non-standard encode/decode scheme (seems unlikely), there is something extra or missing in the CSR that their server is handling and this one is not, or there is just a decoding bug here. |
I tested this patch here, and it appears to work (just the part inside the I would have to incorporate it into my fork before you could use it |
I was able to hack it into my go packages. It does work now. I was returned a happy certificate that I was able to import into my keystore. Thanks for all of the help figuring this out. It is a very nice little package and will save me a lot of time setting up/tearing down my test harness - it is much simpler than some of the alternatives. |
Neat. I'm glad that worked out. I'll hopefully find the time to get this fixed properly and merged into upstream. |
And thanks for putting up with my Go-noobiness. :-) |
Looks like @oeufdure submitted a PR that may include this fix in our fork of mozilla's scep here: omorsi/pkcs7#2 |
I tried using the latest version recently updated from the binary that was released. When I send a release from a an application that uses the jscep library (from an Android device), I get the same ber2der error that I saw a while back ago with the previous. @jessepeterson, Based upon your previous comment is this something that was expected to be fixed in the release, or maybe it was fixed in the source, or is it still outstanding? The log output from the server command is:
|
FYI, I downloaded the source and removed the fullsailor/pkcs7 package that was downloaded with it. I then installed the latest version of the fullsailor/pkcs7 package (go get github.com/fullsailor/pkcs7) and then built it using make. No errors in the build, so seems like it mostly just worked. Ran the scepserver -ca init depot, followed by scepserver -depot depot -port 2016 -challenge=secret, sent the CSR via my jscep client and everything just worked. So I would suggest removing the fullsailor/pkcs7 package you are using from your build and use the latest one with the fixes for the ber decoder. |
Well, whatever you are using is getting the same ber2der error that the old fullsailor package gets:
Looks like the mozilla fork did not pick up the fix from the "newer" fullsailor package. FYI, you can recreate the problem with a jscep client. Works fine with your go client. |
I think that's expected. Would you be able to do the test using the PR omorsi/pkcs7#2 that was mentioned above? |
@bjvetter with the updated dependency would you mind trying again? |
I have tested with the updated dependency and get another error: |
Hi Any chance to publish release with this fix applied? I seem to be facing same issue. Thanks! |
@jbpin I was able to slightly narrow down issue with |
Hello,
first of all thank you very much for providing the SCEP client and server. We are trying to use the SCEP server within our project as a test server to test our client against.
Our client is built in Scala on top of jscep, version 2.5.0. It seems that we are running into an issue that is similar to #20 if not the same. We have just begun to analyse the issue ourselves.
The initial code to drive our enrollment is here together with a very simple main line.
The log output from the client is here and the corresponding server output is here.
First we have tried the docker image providing scep version 1.0, then we have built our own docker image based on the current master, but got the same error message.
Any hint to investigate the issue further would be highly appreciated.
The text was updated successfully, but these errors were encountered: