-
Notifications
You must be signed in to change notification settings - Fork 1
Implement message signing #2
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
base: develop
Are you sure you want to change the base?
Changes from all commits
b30256f
e42cf9f
fefd00a
7b7ab79
f3fe7c8
fdab3c8
3189409
838fd66
b605a3a
442c49a
406355a
2ea1586
09a2d03
befd4f8
763c1d6
c2c864b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| module org.cryptomator.jsmb { | ||
| requires org.slf4j; | ||
| requires static org.jetbrains.annotations; | ||
| requires org.bouncycastle.provider; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok for now, but we should try to add a cmac impl without requiring further dependencies |
||
|
|
||
| // provides java.security.Provider with org.cryptomator.jsmb.ntlmv2.LegacyCryptoProvider; // only required, if we want to find the provider by name | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,25 +7,35 @@ | |
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Arrays; | ||
|
|
||
| import static org.cryptomator.jsmb.ntlmv2.NegotiateFlags.isSet; | ||
|
|
||
| /** | ||
| * Performs the NTLM v2 Authentication | ||
| * @see <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/f9e6fbc4-a953-4f24-b229-ccdcc213b9ec">Server Receives an AUTHENTICATE_MESSAGE from the Client</a> | ||
| * @see <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/5e550938-91d4-459f-b67d-75d70009e3f3">NTLM v2 Authentication</a> | ||
| */ | ||
| class Authenticator { | ||
|
|
||
| public static AuthResponse ntlmV2Auth(NtlmChallengeMessage challengeMessage, NtlmAuthenticateMessage authenticateMessage, String user, String passwd, String userDom) throws AuthenticationFailedException { | ||
| byte[] responseKeyNT = NTOWFv2(passwd, user, userDom); | ||
| byte[] responseKeyLM = LMOWFv2(passwd, user, userDom); | ||
| var serverChallenge = challengeMessage.serverChallenge(); | ||
|
|
||
| if (authenticateMessage.userNameLen() == 0 | ||
| && authenticateMessage.ntChallengeResponseLen() == 0 | ||
| && (authenticateMessage.lmChallengeResponseLen() == 0 || Arrays.equals(new byte[]{0x00}, authenticateMessage.lmChallengeResponse()))) { | ||
| throw new AuthenticationFailedException(NTStatus.STATUS_LOGON_FAILURE, "Anonymouse authentication disabled"); | ||
| } | ||
|
|
||
| byte[] responseKeyNT = NTOWFv2(passwd, user, userDom); | ||
| byte[] responseKeyLM = LMOWFv2(passwd, user, userDom); | ||
|
|
||
| var ntlmV2Response = authenticateMessage.ntlmV2Response(); | ||
| byte[] challengeFromClient = ntlmV2Response.challengeFromClient(); | ||
| byte[] challengeFromClient; | ||
| if (authenticateMessage.ntChallengeResponseLen() > 0x0018) { | ||
| challengeFromClient = ntlmV2Response.challengeFromClient(); | ||
| } else if (isSet(challengeMessage.negotiateFlags(), NegotiateFlags.NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY)) { | ||
| throw new UnsupportedOperationException("Not yet implemented"); | ||
| } else { | ||
| throw new UnsupportedOperationException("Not yet implemented"); | ||
| } | ||
|
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else branch should be trivial: |
||
| var serverChallenge = challengeMessage.serverChallenge(); | ||
| var time = ntlmV2Response.timestamp(); | ||
| var expectedResponse = computeResponse(responseKeyNT, responseKeyLM, serverChallenge, challengeFromClient, time, ntlmV2Response.avPairsSegment().toArray(Layouts.BYTE)); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||
| package org.cryptomator.jsmb.smb2; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import org.cryptomator.jsmb.smb2.negotiate.PreauthIntegrityCapabilities; | ||||||||||||||||||||||||
| import org.cryptomator.jsmb.smb2.negotiate.SigningCapabilities; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||
|
|
@@ -32,7 +33,7 @@ public Connection(Global global) { | |||||||||||||||||||||||
| public char preauthIntegrityHashId = PreauthIntegrityCapabilities.HASH_ALGORITHM_SHA512; | ||||||||||||||||||||||||
| public byte[] preauthIntegrityHashValue = new byte[64]; | ||||||||||||||||||||||||
| public char cipherId; | ||||||||||||||||||||||||
| public char signingAlgorithmId; | ||||||||||||||||||||||||
| public SigningCapabilities.Algorithm signingAlgorithmId; | ||||||||||||||||||||||||
| public char[] compressionIds; | ||||||||||||||||||||||||
| public boolean supportsChainedCompression; | ||||||||||||||||||||||||
|
Comment on lines
34
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore the default signing algorithm Changing - public SigningCapabilities.Algorithm signingAlgorithmId;
+ public SigningCapabilities.Algorithm signingAlgorithmId = SigningCapabilities.Algorithm.HMAC_SHA256;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| public char[] RDMATransformIds; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.cryptomator.jsmb.smb2; | ||
|
|
||
| import org.cryptomator.jsmb.util.Layouts; | ||
|
|
||
| import java.lang.foreign.MemorySegment; | ||
|
|
||
| /** | ||
| * A SMB2 LOGOFF Request | ||
| * | ||
| * @see <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/abdc4ea9-52df-480e-9a36-34f104797d2c">SMB2 LOGOFF Request Specification</a> | ||
| */ | ||
| public record LogoffRequest(PacketHeader header, MemorySegment segment) implements SMB2Message { | ||
|
|
||
| public char structureSize() { | ||
| return segment.get(Layouts.LE_UINT16, 0); //Should always be 4 | ||
| } | ||
|
|
||
| //Reserved: 2 bytes @ offset 2 | ||
| } |
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.
move above
<!-- tests -->; add comment what this is used for (we aim to provide a zero-dependency lib)