├── .bettercodehub.yml ├── .editorconfig ├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ ├── codeql-analysis.yml │ ├── gradle.yml │ └── release.yml ├── .gitignore ├── CONTRIBUTORS ├── LICENSE_HEADER ├── README.adoc ├── WORKING_AUTH_TODO ├── build.gradle ├── conf └── jdepend │ └── jdepend-report.xslt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── it ├── docker-image │ ├── Dockerfile │ ├── entrypoint.sh │ ├── public │ │ ├── folder │ │ │ └── do_not_remove │ │ └── test.txt │ ├── smb.conf │ └── supervisord.conf ├── java │ └── com │ │ └── hierynomus │ │ └── smbj │ │ ├── AnonymousIntegrationTest.java │ │ ├── ChangeNotifyIntegrationTest.java │ │ ├── DfsIntegrationTest.java │ │ ├── IntegrationTest.java │ │ ├── SMB2DirectoryIntegrationTest.java │ │ ├── SMB2FileIntegrationTest.java │ │ ├── testcontainers │ │ └── SambaContainer.java │ │ └── testing │ │ ├── LoggingProgressListener.java │ │ └── TestingUtils.java └── resources │ ├── logback-test.xml │ └── testfiles │ ├── large.pdf │ ├── medium.txt │ └── small.txt ├── main ├── AndroidManifest.xml └── java │ └── com │ └── hierynomus │ ├── msdfsc │ ├── DFSException.java │ ├── DFSPath.java │ ├── DomainCache.java │ ├── ReferralCache.java │ └── messages │ │ ├── DFSReferral.java │ │ ├── DFSReferralV1.java │ │ ├── DFSReferralV2.java │ │ ├── DFSReferralV34.java │ │ ├── SMB2GetDFSReferralExRequest.java │ │ ├── SMB2GetDFSReferralRequest.java │ │ └── SMB2GetDFSReferralResponse.java │ ├── msdtyp │ ├── ACL.java │ ├── AccessMask.java │ ├── FileTime.java │ ├── MsDataTypes.java │ ├── SID.java │ ├── SecurityDescriptor.java │ ├── SecurityInformation.java │ └── ace │ │ ├── ACE.java │ │ ├── AceFlags.java │ │ ├── AceHeader.java │ │ ├── AceObjectFlags.java │ │ ├── AceType.java │ │ ├── AceType1.java │ │ ├── AceType2.java │ │ ├── AceType3.java │ │ ├── AceType4.java │ │ └── AceTypes.java │ ├── mserref │ └── NtStatus.java │ ├── msfscc │ ├── FileAttributes.java │ ├── FileInformationClass.java │ ├── FileNotifyAction.java │ ├── FileSystemInformationClass.java │ ├── directory │ │ └── FileNotifyInformation.java │ ├── fileinformation │ │ ├── FileAccessInformation.java │ │ ├── FileAlignmentInformation.java │ │ ├── FileAllInformation.java │ │ ├── FileAllocationInformation.java │ │ ├── FileBasicInformation.java │ │ ├── FileBothDirectoryInformation.java │ │ ├── FileDirectoryInformation.java │ │ ├── FileDirectoryQueryableInformation.java │ │ ├── FileDispositionInformation.java │ │ ├── FileEaInformation.java │ │ ├── FileEndOfFileInformation.java │ │ ├── FileFullDirectoryInformation.java │ │ ├── FileIdBothDirectoryInformation.java │ │ ├── FileIdFullDirectoryInformation.java │ │ ├── FileInformation.java │ │ ├── FileInformationFactory.java │ │ ├── FileInternalInformation.java │ │ ├── FileLinkInformation.java │ │ ├── FileModeInformation.java │ │ ├── FileNamesInformation.java │ │ ├── FilePositionInformation.java │ │ ├── FileQueryableInformation.java │ │ ├── FileRenameInformation.java │ │ ├── FileSettableInformation.java │ │ ├── FileStandardInformation.java │ │ ├── FileStreamInformation.java │ │ ├── FileStreamInformationItem.java │ │ ├── ShareInfo.java │ │ └── VolumeInfo.java │ └── fsctl │ │ ├── FsCtlPipePeekResponse.java │ │ └── FsCtlPipeWaitRequest.java │ ├── mssmb │ ├── SMB1Header.java │ ├── SMB1NotSupportedException.java │ ├── SMB1Packet.java │ ├── SMB1PacketData.java │ ├── SMB1PacketFactory.java │ └── messages │ │ └── SMB1ComNegotiateRequest.java │ ├── mssmb2 │ ├── DeadLetterPacketData.java │ ├── SMB2ChangeNotifyFlags.java │ ├── SMB2CompletionFilter.java │ ├── SMB2CompressionTransformHeader.java │ ├── SMB2CreateAction.java │ ├── SMB2CreateDisposition.java │ ├── SMB2CreateOptions.java │ ├── SMB2DecryptedPacketData.java │ ├── SMB2Dialect.java │ ├── SMB2Error.java │ ├── SMB2FileId.java │ ├── SMB2Functions.java │ ├── SMB2GlobalCapability.java │ ├── SMB2ImpersonationLevel.java │ ├── SMB2LockFlag.java │ ├── SMB2MessageCommandCode.java │ ├── SMB2MessageConverter.java │ ├── SMB2MessageFlag.java │ ├── SMB2MultiCreditPacket.java │ ├── SMB2Packet.java │ ├── SMB2PacketData.java │ ├── SMB2PacketFactory.java │ ├── SMB2PacketHeader.java │ ├── SMB2ShareAccess.java │ ├── SMB2ShareCapabilities.java │ ├── SMB2ShareFlags.java │ ├── SMB2TransformHeader.java │ ├── SMB3CompressedPacketData.java │ ├── SMB3CompressedPacketFactory.java │ ├── SMB3CompressionAlgorithm.java │ ├── SMB3EncryptedPacketData.java │ ├── SMB3EncryptedPacketFactory.java │ ├── SMB3EncryptionCipher.java │ ├── SMB3HashAlgorithm.java │ ├── SMBApiException.java │ ├── copy │ │ ├── CopyChunkRequest.java │ │ └── CopyChunkResponse.java │ └── messages │ │ ├── SMB2Cancel.java │ │ ├── SMB2ChangeNotifyRequest.java │ │ ├── SMB2ChangeNotifyResponse.java │ │ ├── SMB2Close.java │ │ ├── SMB2CreateRequest.java │ │ ├── SMB2CreateResponse.java │ │ ├── SMB2Echo.java │ │ ├── SMB2Flush.java │ │ ├── SMB2IoctlRequest.java │ │ ├── SMB2IoctlResponse.java │ │ ├── SMB2LockRequest.java │ │ ├── SMB2LockResponse.java │ │ ├── SMB2Logoff.java │ │ ├── SMB2NegotiateRequest.java │ │ ├── SMB2NegotiateResponse.java │ │ ├── SMB2QueryDirectoryRequest.java │ │ ├── SMB2QueryDirectoryResponse.java │ │ ├── SMB2QueryInfoRequest.java │ │ ├── SMB2QueryInfoResponse.java │ │ ├── SMB2ReadRequest.java │ │ ├── SMB2ReadResponse.java │ │ ├── SMB2SessionSetup.java │ │ ├── SMB2SetInfoRequest.java │ │ ├── SMB2SetInfoResponse.java │ │ ├── SMB2TreeConnectRequest.java │ │ ├── SMB2TreeConnectResponse.java │ │ ├── SMB2TreeDisconnect.java │ │ ├── SMB2WriteRequest.java │ │ ├── SMB2WriteResponse.java │ │ ├── negotiate │ │ ├── SMB2CompressionCapabilities.java │ │ ├── SMB2EncryptionCapabilities.java │ │ ├── SMB2NegotiateContext.java │ │ ├── SMB2NegotiateContextType.java │ │ ├── SMB2NetNameNegotiateContextId.java │ │ └── SMB2PreauthIntegrityCapabilities.java │ │ └── submodule │ │ └── SMB2LockElement.java │ ├── ntlm │ ├── NtlmConfig.java │ ├── NtlmException.java │ ├── av │ │ ├── AvId.java │ │ ├── AvPair.java │ │ ├── AvPairChannelBindings.java │ │ ├── AvPairEnd.java │ │ ├── AvPairFactory.java │ │ ├── AvPairFlags.java │ │ ├── AvPairSingleHost.java │ │ ├── AvPairString.java │ │ └── AvPairTimestamp.java │ ├── functions │ │ ├── ComputedNtlmV2Response.java │ │ ├── NtlmFunctions.java │ │ ├── NtlmV1Functions.java │ │ └── NtlmV2Functions.java │ └── messages │ │ ├── NtlmAuthenticate.java │ │ ├── NtlmChallenge.java │ │ ├── NtlmMessage.java │ │ ├── NtlmNegotiate.java │ │ ├── NtlmNegotiateFlag.java │ │ ├── NtlmPacket.java │ │ ├── TargetInfo.java │ │ ├── Utils.java │ │ └── WindowsVersion.java │ ├── protocol │ ├── Packet.java │ ├── PacketData.java │ ├── commons │ │ ├── ByteArrayUtils.java │ │ ├── Charsets.java │ │ ├── EnumWithValue.java │ │ ├── Factory.java │ │ ├── IOUtils.java │ │ ├── Objects.java │ │ ├── backport │ │ │ ├── JavaVersion.java │ │ │ └── Jdk7HttpProxySocket.java │ │ ├── buffer │ │ │ ├── Buffer.java │ │ │ └── Endian.java │ │ ├── concurrent │ │ │ ├── AFuture.java │ │ │ ├── CancellableFuture.java │ │ │ ├── ExceptionWrapper.java │ │ │ ├── Futures.java │ │ │ ├── Promise.java │ │ │ ├── PromiseBackedFuture.java │ │ │ ├── SequencedFuture.java │ │ │ └── TransformedFuture.java │ │ └── socket │ │ │ └── ProxySocketFactory.java │ ├── package-info.java │ └── transport │ │ ├── PacketFactory.java │ │ ├── PacketHandlers.java │ │ ├── PacketReceiver.java │ │ ├── PacketSerializer.java │ │ ├── TransportException.java │ │ └── TransportLayer.java │ ├── security │ ├── AEADBlockCipher.java │ ├── Cipher.java │ ├── DerivationFunction.java │ ├── Mac.java │ ├── MessageDigest.java │ ├── SecurityException.java │ ├── SecurityProvider.java │ ├── bc │ │ ├── BCAEADCipherFactory.java │ │ ├── BCCipherFactory.java │ │ ├── BCDerivationFunctionFactory.java │ │ ├── BCMac.java │ │ ├── BCMessageDigest.java │ │ └── BCSecurityProvider.java │ ├── jce │ │ ├── JceAEADCipher.java │ │ ├── JceCipher.java │ │ ├── JceDerivationFunction.java │ │ ├── JceDerivationFunctionFactory.java │ │ ├── JceMac.java │ │ ├── JceMessageDigest.java │ │ ├── JceSecurityProvider.java │ │ ├── derivationfunction │ │ │ ├── CounterDerivationParameters.java │ │ │ ├── DerivationParameters.java │ │ │ └── KDFCounterHMacSHA256.java │ │ └── messagedigest │ │ │ └── MD4.java │ └── mac │ │ └── HmacT64.java │ ├── smb │ ├── Packets.java │ ├── SMBBuffer.java │ ├── SMBHeader.java │ ├── SMBPacket.java │ └── SMBPacketData.java │ ├── smbj │ ├── GSSContextConfig.java │ ├── ProgressListener.java │ ├── SMBClient.java │ ├── SmbConfig.java │ ├── auth │ │ ├── AuthenticateResponse.java │ │ ├── AuthenticationContext.java │ │ ├── Authenticator.java │ │ ├── ExtendedGSSContext.java │ │ ├── GSSAuthenticationContext.java │ │ ├── NtlmAuthenticator.java │ │ ├── NtlmSealer.java │ │ └── SpnegoAuthenticator.java │ ├── common │ │ ├── Check.java │ │ ├── Pooled.java │ │ ├── SMBException.java │ │ ├── SMBRuntimeException.java │ │ └── SmbPath.java │ ├── connection │ │ ├── Connection.java │ │ ├── ConnectionContext.java │ │ ├── NegotiatedProtocol.java │ │ ├── NoSignatory.java │ │ ├── OutstandingRequests.java │ │ ├── PacketEncryptor.java │ │ ├── PacketSignatory.java │ │ ├── Request.java │ │ ├── SMBPacketSerializer.java │ │ ├── SMBProtocolNegotiator.java │ │ ├── SMBSessionBuilder.java │ │ ├── SequenceWindow.java │ │ ├── SessionTable.java │ │ ├── Signatory.java │ │ └── packet │ │ │ ├── AbstractIncomingPacketHandler.java │ │ │ ├── DeadLetterPacketHandler.java │ │ │ ├── IncomingPacketHandler.java │ │ │ ├── SMB1PacketHandler.java │ │ │ ├── SMB2AsyncResponsePacketHandler.java │ │ │ ├── SMB2CompoundedPacketHandler.java │ │ │ ├── SMB2CreditGrantingPacketHandler.java │ │ │ ├── SMB2IsOutstandingPacketHandler.java │ │ │ ├── SMB2PacketHandler.java │ │ │ ├── SMB2ProcessResponsePacketHandler.java │ │ │ ├── SMB2SignatureVerificationPacketHandler.java │ │ │ └── SMB3DecryptingPacketHandler.java │ ├── event │ │ ├── ConnectionClosed.java │ │ ├── SMBEvent.java │ │ ├── SMBEventBus.java │ │ ├── SessionEvent.java │ │ ├── SessionLoggedOff.java │ │ └── TreeDisconnected.java │ ├── io │ │ ├── ArrayByteChunkProvider.java │ │ ├── BufferByteChunkProvider.java │ │ ├── ByteBufferByteChunkProvider.java │ │ ├── ByteChunkProvider.java │ │ ├── CachingByteChunkProvider.java │ │ ├── EmptyByteChunkProvider.java │ │ ├── FileByteChunkProvider.java │ │ └── InputStreamByteChunkProvider.java │ ├── paths │ │ ├── DFSPathResolver.java │ │ ├── PathResolveException.java │ │ ├── PathResolver.java │ │ └── SymlinkPathResolver.java │ ├── server │ │ ├── Server.java │ │ └── ServerList.java │ ├── session │ │ ├── SMB2GuestSigningRequiredException.java │ │ ├── Session.java │ │ ├── SessionContext.java │ │ └── TreeConnectTable.java │ ├── share │ │ ├── Directory.java │ │ ├── DiskEntry.java │ │ ├── DiskShare.java │ │ ├── File.java │ │ ├── FileInputStream.java │ │ ├── FileOutputStream.java │ │ ├── NamedPipe.java │ │ ├── Open.java │ │ ├── OperationBuckets.java │ │ ├── PipeShare.java │ │ ├── PrinterShare.java │ │ ├── RingBuffer.java │ │ ├── SMB2Writer.java │ │ ├── Share.java │ │ ├── StatusHandler.java │ │ └── TreeConnect.java │ ├── transport │ │ ├── PacketReader.java │ │ ├── TransportLayerFactory.java │ │ └── tcp │ │ │ ├── async │ │ │ ├── AsyncDirectTcpTransport.java │ │ │ ├── AsyncDirectTcpTransportFactory.java │ │ │ ├── AsyncPacketReader.java │ │ │ └── PacketBufferReader.java │ │ │ ├── direct │ │ │ ├── DirectTcpPacketReader.java │ │ │ ├── DirectTcpTransport.java │ │ │ └── DirectTcpTransportFactory.java │ │ │ └── tunnel │ │ │ ├── TunnelTransport.java │ │ │ └── TunnelTransportFactory.java │ └── utils │ │ ├── DigestUtil.java │ │ └── SmbFiles.java │ ├── spnego │ ├── NegTokenInit.java │ ├── NegTokenInit2.java │ ├── NegTokenTarg.java │ ├── ObjectIdentifiers.java │ ├── RawToken.java │ ├── SpnegoException.java │ └── SpnegoToken.java │ └── utils │ └── Strings.java └── test ├── groovy └── com │ └── hierynomus │ ├── msdfsc │ ├── DFSTest.groovy │ ├── DirectFuture.groovy │ ├── SMB2GetDFSReferralResponseTest.groovy │ └── StubResponder.groovy │ ├── msdtyp │ └── SecurityDescriptorSpec.groovy │ ├── mssmb2 │ ├── SMB2ErrorSpec.groovy │ ├── SMB2MessageFlagSpec.groovy │ ├── SMB2PacketHeaderSpec.groovy │ └── messages │ │ ├── AbstractPacketReadSpec.groovy │ │ ├── SMB2ChangeNotifyResponseSpec.groovy │ │ ├── SMB2CreateResponseSpec.groovy │ │ ├── SMB2QueryDirectoryResponseSpec.groovy │ │ ├── SMB2ReadRequestSpec.groovy │ │ ├── SMB2ReadResponseSpec.groovy │ │ ├── SMB2TreeConnectResponseSpec.groovy │ │ └── SMB2WriteResponseSpec.groovy │ ├── ntlm │ ├── functions │ │ └── NtlmFunctionsSpec.groovy │ └── messages │ │ ├── NtlmChallengeSpec.groovy │ │ ├── NtlmNegotiateFlagSpec.groovy │ │ └── SampleMessages.groovy │ ├── protocol │ └── commons │ │ └── buffer │ │ └── BufferSpec.groovy │ ├── security │ └── jce │ │ ├── JceMessageDigestSpec.groovy │ │ └── derivationfunction │ │ └── KDFCounterHMacSHA256Spec.groovy │ ├── smbj │ ├── SMBClientSpec.groovy │ ├── common │ │ └── SmbPathSpec.groovy │ ├── connection │ │ ├── ConnectionSpec.groovy │ │ ├── SMBSessionBuilderSpec.groovy │ │ └── SequenceWindowSpec.groovy │ ├── io │ │ ├── BufferByteChunkProviderSpec.groovy │ │ ├── ByteBufferByteChunkProviderSpec.groovy │ │ ├── FileByteChunkProviderSpec.groovy │ │ └── InputStreamByteChunkProviderSpec.groovy │ ├── paths │ │ └── SymlinkPathResolverSpec.groovy │ ├── server │ │ └── StubSmbServer.groovy │ ├── share │ │ ├── FileOutputStreamSpec.groovy │ │ ├── FileReadSpec.groovy │ │ └── RingBufferSpec.groovy │ └── transport │ │ └── tcp │ │ └── async │ │ └── AsyncDirectTcpTransportSpec.groovy │ ├── spnego │ ├── NegTokenInitSpec.groovy │ └── NegTokenTargSpec.groovy │ └── test │ └── PredictableRandom.java ├── java └── com │ └── hierynomus │ ├── msdfsc │ ├── DFSPathTest.java │ └── ReferralCacheNodeTest.java │ ├── msdtyp │ ├── MsDataTypesTest.java │ └── SIDTest.java │ ├── mserref │ └── NtStatusTest.java │ ├── msfscc │ └── fileinformation │ │ └── FileAllInformationTest.java │ └── smbj │ ├── SmbConfigTest.java │ ├── connection │ ├── ConnectionTest.java │ ├── PacketEncryptorTest.java │ ├── PacketSignatoryTest.java │ └── ProtocolNegotiatorTest.java │ ├── session │ └── SessionTest.java │ └── testing │ ├── PacketProcessor.java │ ├── StubAuthenticator.java │ ├── StubTransportLayerFactory.java │ └── Utils.java └── resources ├── com └── hierynomus │ └── smbj │ └── transport │ └── tcp │ └── async │ └── nego-response.pcap ├── logback-test.xml └── spnego ├── negTokenInit_ntlm ├── negTokenInit_resp └── negTokenTarg_ntlmchallenge /.bettercodehub.yml: -------------------------------------------------------------------------------- 1 | exclude: 2 | - /build.gradle 3 | component_depth: 1 4 | languages: 5 | - groovy 6 | - java 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | 12 | [*.properties] 13 | charset = iso-8895-1 14 | 15 | [*.bat] 16 | end_of_line = crlf 17 | 18 | # 4 space indentation 19 | [*.{java,json,py,js}] 20 | indent_style = space 21 | indent_size = 4 22 | 23 | # 2 space indentation 24 | [*.{groovy,gradle,html}] 25 | indent_style = space 26 | indent_size = 2 27 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.bat text eol=crlf 3 | *.cmd text eol=crlf 4 | *.ps1 text eol=crlf 5 | *.sh text eol=lf 6 | *.java text 7 | *.scala text 8 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @hierynomus 2 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Build SMBJ 5 | 6 | 7 | on: 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | jobs: 14 | java11: 15 | name: Build with Java 11 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Set up JDK 11 20 | uses: actions/setup-java@v2 21 | with: 22 | distribution: 'zulu' 23 | java-version: 11 24 | - name: Cache Gradle packages 25 | uses: actions/cache@v3 26 | with: 27 | path: ~/.gradle/caches 28 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} 29 | restore-keys: ${{ runner.os }}-gradle 30 | - name: Build with Gradle 31 | run: ./gradlew check 32 | integration: 33 | name: Integration test 34 | needs: [java11] 35 | runs-on: [ubuntu-latest] 36 | steps: 37 | - uses: actions/checkout@v3 38 | - name: Set up JDK 11 39 | uses: actions/setup-java@v2 40 | with: 41 | distribution: 'zulu' 42 | java-version: 11 43 | - name: Cache Gradle packages 44 | uses: actions/cache@v3 45 | with: 46 | path: ~/.gradle/caches 47 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} 48 | restore-keys: ${{ runner.os }}-gradle 49 | - name: Run integration tests 50 | run: ./gradlew integrationTest 51 | 52 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: SMBJ Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | permissions: 9 | contents: write 10 | 11 | jobs: 12 | java12: 13 | name: Build with Java 12 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | with: 18 | fetch-depth: 0 19 | - name: Set up JDK 12 20 | uses: actions/setup-java@v2 21 | with: 22 | distribution: 'zulu' 23 | java-version: 12 24 | - name: Grant execute permission for gradlew 25 | run: chmod +x gradlew 26 | - name: Build with Gradle 27 | run: ./gradlew check 28 | release: 29 | name: Release 30 | needs: [java12] 31 | runs-on: ubuntu-latest 32 | steps: 33 | - uses: actions/checkout@v3 34 | with: 35 | fetch-depth: 0 36 | - uses: actions/setup-java@v2 37 | with: 38 | distribution: 'zulu' 39 | java-version: 12 40 | - name: Grant execute permission for gradlew 41 | run: chmod +x gradlew 42 | - name: Release 43 | run: ./gradlew clean publishToSonatype closeAndReleaseSonatypeStagingRepository 44 | env: 45 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNINGKEY }} 46 | ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNINGKEYID }} 47 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNINGPASSWORD }} 48 | ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.OSSRH_USERNAME }} 49 | ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.OSSRH_PASSWORD }} 50 | 51 | 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # use glob syntax. 2 | syntax: glob 3 | target/ 4 | .svn/ 5 | .settings 6 | .cache 7 | .classpath 8 | .project 9 | .metadata 10 | .pydevproject 11 | *.iml 12 | *.ipr 13 | *.iws 14 | *.log 15 | .gradle/ 16 | .idea/ 17 | out/ 18 | build/ 19 | classes/ 20 | bin/ 21 | test-output/ 22 | .DS_Store 23 | /smbj/ 24 | *.pdf 25 | .vscode/ 26 | .java-version 27 | 28 | .metals 29 | .bloop 30 | MacIntegrationTest.* 31 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Jeroen van Erp 2 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Copyright (C)2016 - SMBJ Contributors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /WORKING_AUTH_TODO: -------------------------------------------------------------------------------- 1 | Missing commit: 10001efcf7b5beee6994fb0e4a3680a6503f6eab 2 | Extract TargetInfo to separate class and correct offsets for NtlmNegotiate (#630) 3 | 4 | * Extract TargetInfo to separate class and correct offsets for NtlmNegotiate 5 | 6 | * Add Target SPN AvId if NTLMSSP_REQUEST_TARGET set 7 | 8 | * Use clientTargetInfo to calculate NTLM clientChallenge 9 | ------ 10 | Missing commit: 3e454de9a29db2ef0896af60573378ea7ba4fa4b 11 | Fix ClassCastException (fixes \#712) 12 | ------ 13 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | BCPROV_JDK15ON=org.bouncycastle:bcprov-jdk18on:1.79 2 | CGLIB_NODEP=cglib:cglib-nodep:3.3.0 3 | COMMONS_IO=commons-io:commons-io:2.16.1 4 | LOGBACK_CLASSIC=ch.qos.logback:logback-classic:1.5.6 5 | MBASSADOR=net.engio:mbassador:1.3.0 6 | OBJENESIS=org.objenesis:objenesis:3.4 7 | SLF4J_API=org.slf4j:slf4j-api:2.0.9 8 | SPOCK_CORE=org.spockframework:spock-core:2.3-groovy-3.0 9 | ASN_ONE=com.hierynomus:asn-one:0.6.0 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 22 09:16:37 CET 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "smbj" 2 | -------------------------------------------------------------------------------- /src/it/docker-image/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.7 2 | 3 | RUN apk update && apk add --no-cache tini samba samba-common-tools supervisor bash 4 | 5 | ENV SMB_USER smbj 6 | ENV SMB_PASSWORD smbj 7 | 8 | COPY smb.conf /etc/samba/smb.conf 9 | COPY supervisord.conf /etc/supervisord.conf 10 | COPY entrypoint.sh /entrypoint.sh 11 | ADD public /opt/samba/share 12 | 13 | RUN mkdir -p /opt/samba/readonly /opt/samba/user /opt/samba/dfs && \ 14 | chmod 777 /opt/samba/readonly /opt/samba/user /opt/samba/dfs && \ 15 | adduser -s /bin/false "$SMB_USER" -D $SMB_PASSWORD && \ 16 | (echo "$SMB_PASSWORD"; echo "$SMB_PASSWORD" ) | pdbedit -a -u "$SMB_USER" && \ 17 | chmod ugo+x /entrypoint.sh 18 | 19 | EXPOSE 137/udp 138/udp 139 445 20 | 21 | ENTRYPOINT ["/sbin/tini", "/entrypoint.sh"] 22 | CMD ["supervisord"] 23 | 24 | -------------------------------------------------------------------------------- /src/it/docker-image/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | : "${SMB_USER:=smbuser}" 5 | : "${SMB_PASSWORD:=smbpassword}" 6 | # 7 | #for netdev in /sys/class/net/*; do 8 | # netdev=${netdev##*/} 9 | # if [[ "$netdev" != "lo" ]]; then 10 | # break 11 | # fi 12 | #done 13 | #subnet=$(ip addr show "$netdev" | sed -n 's/.*inet \([0-9\.]*\/[0-9]*\) .*/\1/p') 14 | #ip_address=${subnet%%/*} 15 | 16 | ip_address="127.0.0.1" 17 | 18 | # Create DFS links 19 | # - /public -> public share 20 | # - /user -> user share 21 | # - /firstfail-public -> first listed server fails, second -> public share 22 | ln -s "msdfs:${ip_address}\\public" /opt/samba/dfs/public 23 | ln -s "msdfs:${ip_address}\\user" /opt/samba/dfs/user 24 | ln -s "msdfs:192.0.2.1\\notthere,${ip_address}\\public" /opt/samba/dfs/firstfail-public 25 | 26 | exec "$@" 27 | -------------------------------------------------------------------------------- /src/it/docker-image/public/folder/do_not_remove: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/src/it/docker-image/public/folder/do_not_remove -------------------------------------------------------------------------------- /src/it/docker-image/public/test.txt: -------------------------------------------------------------------------------- 1 | Hi there! 2 | -------------------------------------------------------------------------------- /src/it/docker-image/smb.conf: -------------------------------------------------------------------------------- 1 | [global] 2 | security = user 3 | 4 | load printers = no 5 | printcap name = /dev/null 6 | printing = bsd 7 | 8 | unix charset = UTF-8 9 | dos charset = CP932 10 | 11 | workgroup = WORKGROUP 12 | 13 | server string = %h server (Samba, Ubuntu) 14 | dns proxy = no 15 | interfaces = 192.168.2.0/24 eth0 16 | bind interfaces only = yes 17 | log level = 5 auth:10 18 | log file = /var/log/samba.log 19 | max log size = 20480 20 | syslog = 1 21 | panic action = /usr/share/samba/panic-action %d 22 | server role = standalone server 23 | passdb backend = tdbsam 24 | obey pam restrictions = yes 25 | unix password sync = yes 26 | passwd program = /usr/bin/passwd %u 27 | passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . 28 | pam password change = yes 29 | map to guest = Bad User 30 | usershare allow guests = yes 31 | host msdfs = yes 32 | 33 | [public] 34 | path = /opt/samba/share 35 | writable = yes 36 | printable = no 37 | public = yes 38 | guest only = yes 39 | create mode = 0777 40 | directory mode = 0777 41 | 42 | [readonly] 43 | path = /opt/samba/readonly 44 | writable = no 45 | printable = no 46 | public = no 47 | 48 | [user] 49 | path = /opt/samba/user 50 | writable = yes 51 | printable = no 52 | public = no 53 | create mode = 0777 54 | directory mode = 0777 55 | 56 | [dfs] 57 | path = /opt/samba/dfs 58 | writable = no 59 | printable = no 60 | public = yes 61 | guest ok = yes 62 | msdfs root = yes 63 | -------------------------------------------------------------------------------- /src/it/docker-image/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | /* user=root */ 4 | loglevel=info 5 | 6 | [program:smbd] 7 | /* command=/usr/sbin/smbd -i --daemon --foreground --log-stdout */ 8 | command=/usr/sbin/smbd --daemon --foreground --configfile=/etc/samba/smb.conf 9 | /*redirect_stderr=true*/ 10 | 11 | [program:nmbd] 12 | /* command=/usr/sbin/nmbd -i --daemon --foreground --log-stdout */ 13 | command=/usr/sbin/nmbd --daemon --foreground 14 | /*redirect_stderr=true*/ 15 | -------------------------------------------------------------------------------- /src/it/java/com/hierynomus/smbj/testing/LoggingProgressListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.testing; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import com.hierynomus.smbj.ProgressListener; 22 | 23 | public class LoggingProgressListener implements ProgressListener { 24 | private static final Logger logger = LoggerFactory.getLogger(LoggingProgressListener.class); 25 | 26 | @Override 27 | public void onProgressChanged(long numBytes, long totalBytes) { 28 | logger.info("R/W {} bytes, total = {} bytes", numBytes, totalBytes); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/it/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%.-20thread] %-5level %logger{36} - %msg%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/it/resources/testfiles/large.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/src/it/resources/testfiles/large.pdf -------------------------------------------------------------------------------- /src/it/resources/testfiles/small.txt: -------------------------------------------------------------------------------- 1 | hello 2 | hi 3 | 4 | -------------------------------------------------------------------------------- /src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msdfsc/DFSException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdfsc; 17 | 18 | import com.hierynomus.smbj.paths.PathResolveException; 19 | 20 | @SuppressWarnings("serial") 21 | public class DFSException extends PathResolveException { 22 | public DFSException(long status, String message) { 23 | super(status, message); 24 | } 25 | 26 | public DFSException(long status) { 27 | super(status); 28 | } 29 | 30 | public DFSException(Throwable cause) { 31 | super(cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msdfsc/messages/SMB2GetDFSReferralRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdfsc.messages; 17 | 18 | import com.hierynomus.protocol.commons.Charsets; 19 | import com.hierynomus.smb.SMBBuffer; 20 | 21 | /** 22 | * [MS-DFSC].pdf 2.2.2 REQ_GET_DFS_REFERRAL 23 | */ 24 | public class SMB2GetDFSReferralRequest { 25 | 26 | private String requestFileName; 27 | 28 | public SMB2GetDFSReferralRequest(String path) { 29 | requestFileName = path; 30 | } 31 | 32 | public void writeTo(SMBBuffer buffer) { 33 | buffer.putUInt16(4); // MaxReferralLevel (2 bytes) 34 | buffer.putNullTerminatedString(requestFileName, Charsets.UTF_16); // RequestFileName (variable) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msdtyp/SecurityInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdtyp; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-DTYP].pdf 2.4.7 Security Information 22 | */ 23 | public enum SecurityInformation implements EnumWithValue { 24 | OWNER_SECURITY_INFORMATION(0x00000001L), 25 | GROUP_SECURITY_INFORMATION(0x00000002L), 26 | DACL_SECURITY_INFORMATION(0x00000004L), 27 | SACL_SECURITY_INFORMATION(0x00000008L), 28 | LABEL_SECURITY_INFORMATION(0x00000010L), 29 | UNPROTECTED_SACL_SECURITY_INFORMATION(0x10000000L), 30 | UNPROTECTED_DACL_SECURITY_INFORMATION(0x20000000L), 31 | PROTECTED_SACL_SECURITY_INFORMATION(0x40000000L), 32 | PROTECTED_DACL_SECURITY_INFORMATION(0x80000000L), 33 | ATTRIBUTE_SECURITY_INFORMATION(0x00000020L), 34 | SCOPE_SECURITY_INFORMATION(0x00000040L), 35 | BACKUP_SECURITY_INFORMATION(0x00010000L); 36 | 37 | private long value; 38 | 39 | SecurityInformation(long value) { 40 | this.value = value; 41 | } 42 | 43 | public long getValue() { 44 | return value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msdtyp/ace/AceFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdtyp.ace; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | public enum AceFlags implements EnumWithValue { 21 | CONTAINER_INHERIT_ACE(0x02L), 22 | FAILED_ACCESS_ACE_FLAG(0x80L), 23 | INHERIT_ONLY_ACE(0x08L), 24 | INHERITED_ACE(0x10L), 25 | NO_PROPAGATE_INHERIT_ACE(0x04L), 26 | OBJECT_INHERIT_ACE(0x01L), 27 | SUCCESSFUL_ACCESS_ACE_FLAG(0x40L); 28 | 29 | private long value; 30 | 31 | AceFlags(long value) { 32 | this.value = value; 33 | } 34 | 35 | public long getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msdtyp/ace/AceObjectFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdtyp.ace; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | public enum AceObjectFlags implements EnumWithValue { 21 | 22 | NONE(0x00000000L), 23 | ACE_OBJECT_TYPE_PRESENT(0x00000001L), 24 | ACE_INHERITED_OBJECT_TYPE_PRESENT(0x00000002L); 25 | 26 | private long value; 27 | 28 | AceObjectFlags(long value) { 29 | this.value = value; 30 | } 31 | 32 | public long getValue() { 33 | return value; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/FileNotifyAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-FSCC].pdf 2.4.42 File Notify Information Action 22 | */ 23 | public enum FileNotifyAction implements EnumWithValue { 24 | FILE_ACTION_ADDED(0x00000001L), 25 | FILE_ACTION_REMOVED(0x00000002L), 26 | FILE_ACTION_MODIFIED(0x00000003L), 27 | FILE_ACTION_RENAMED_OLD_NAME(0x00000004L), 28 | FILE_ACTION_RENAMED_NEW_NAME(0x00000005L), 29 | FILE_ACTION_ADDED_STREAM(0x00000006L), 30 | FILE_ACTION_REMOVED_STREAM(0x00000007L), 31 | FILE_ACTION_MODIFIED_STREAM(0x00000008L), 32 | FILE_ACTION_REMOVED_BY_DELETE(0x00000009L), 33 | FILE_ACTION_ID_NOT_TUNNELLED(0x0000000AL), 34 | FILE_ACTION_TUNNELLED_ID_COLLISION(0x0000000BL); 35 | 36 | private long value; 37 | 38 | FileNotifyAction(long value) { 39 | this.value = value; 40 | } 41 | 42 | public long getValue() { 43 | return value; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/FileSystemInformationClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * MS-FSCC 2.5 File System Information Classes 22 | */ 23 | public enum FileSystemInformationClass implements EnumWithValue { 24 | 25 | FileFsVolumeInformation(0x01L), 26 | FileFsLabelInformation(0x02L), 27 | FileFsSizeInformation(0x03L), 28 | FileFsDeviceInformation(0x04L), 29 | FileFsAttributeInformation(0x05L), 30 | FileFsControlInformation(0x06L), 31 | FileFsFullSizeInformation(0x07L), 32 | FileFsObjectIdInformation(0x08L), 33 | FileFsDriverPathInformation(0x09L), 34 | FileFsVolumeFlagsInformation(0x0AL), 35 | FileFsSectorSizeInformation(0x0BL); 36 | 37 | private long value; 38 | 39 | FileSystemInformationClass(long value) { 40 | this.value = value; 41 | } 42 | 43 | public long getValue() { 44 | return value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileAccessInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileAccessInformation implements FileQueryableInformation { 19 | 20 | private int accessFlags; 21 | 22 | FileAccessInformation(int accessFlags) { 23 | this.accessFlags = accessFlags; 24 | } 25 | 26 | public int getAccessFlags() { 27 | return accessFlags; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileAlignmentInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileAlignmentInformation implements FileQueryableInformation { 19 | 20 | private long alignmentRequirement; 21 | 22 | FileAlignmentInformation(long alignmentRequirement) { 23 | this.alignmentRequirement = alignmentRequirement; 24 | } 25 | 26 | public long getAlignmentRequirement() { 27 | return alignmentRequirement; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileAllocationInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileAllocationInformation implements FileSettableInformation { 19 | 20 | private long allocationSize; 21 | 22 | public FileAllocationInformation(long allocationSize) { 23 | this.allocationSize = allocationSize; 24 | } 25 | 26 | public long getAllocationSize() { 27 | return allocationSize; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileDirectoryQueryableInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public abstract class FileDirectoryQueryableInformation implements FileInformation { 19 | private final String fileName; 20 | private long nextOffset; 21 | private long fileIndex; 22 | 23 | FileDirectoryQueryableInformation(long nextOffset, long fileIndex, String fileName) { 24 | this.nextOffset = nextOffset; 25 | this.fileIndex = fileIndex; 26 | this.fileName = fileName; 27 | } 28 | 29 | public long getNextOffset() { 30 | return nextOffset; 31 | } 32 | 33 | public long getFileIndex() { 34 | return fileIndex; 35 | } 36 | 37 | public String getFileName() { 38 | return fileName; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileDispositionInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileDispositionInformation implements FileSettableInformation { 19 | private boolean deleteOnClose; 20 | 21 | public FileDispositionInformation() { 22 | this.deleteOnClose = true; 23 | } 24 | 25 | public FileDispositionInformation(boolean deleteOnClose) { 26 | this.deleteOnClose = deleteOnClose; 27 | } 28 | 29 | public boolean isDeleteOnClose() { 30 | return deleteOnClose; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileEaInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileEaInformation implements FileQueryableInformation { 19 | private long eaSize; 20 | 21 | FileEaInformation(long eaSize) { 22 | this.eaSize = eaSize; 23 | } 24 | 25 | public long getEaSize() { 26 | return eaSize; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileEndOfFileInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileEndOfFileInformation implements FileSettableInformation { 19 | 20 | private long endOfFile; 21 | 22 | public FileEndOfFileInformation(long endOfFile) throws IllegalArgumentException { 23 | if (endOfFile < 0L) { 24 | throw new IllegalArgumentException("endOfFile MUST be greater than or equal to 0"); 25 | } 26 | this.endOfFile = endOfFile; 27 | } 28 | 29 | public long getEndOfFile() { 30 | return endOfFile; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | import com.hierynomus.msfscc.FileInformationClass; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | 21 | public interface FileInformation { 22 | interface Encoder { 23 | FileInformationClass getInformationClass(); 24 | 25 | void write(F info, Buffer outputBuffer); 26 | } 27 | 28 | interface Decoder { 29 | FileInformationClass getInformationClass(); 30 | 31 | F read(Buffer inputBuffer) throws Buffer.BufferException; 32 | } 33 | 34 | interface Codec extends Encoder, Decoder { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileInternalInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileInternalInformation implements FileQueryableInformation { 19 | private long indexNumber; 20 | 21 | FileInternalInformation(long eaSize) { 22 | this.indexNumber = eaSize; 23 | } 24 | 25 | public long getIndexNumber() { 26 | return indexNumber; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileLinkInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileLinkInformation extends FileRenameInformation { 19 | 20 | public FileLinkInformation(final boolean replaceIfExists, final String fileName) { 21 | super(replaceIfExists, 0L, fileName); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileModeInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileModeInformation implements FileQueryableInformation, FileSettableInformation { 19 | 20 | private int mode; 21 | 22 | public FileModeInformation(int mode) { 23 | this.mode = mode; 24 | } 25 | 26 | public int getMode() { 27 | return mode; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileNamesInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileNamesInformation extends FileDirectoryQueryableInformation { 19 | FileNamesInformation(long nextOffset, long fileIndex, String fileName) { 20 | super(nextOffset, fileIndex, fileName); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FilePositionInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FilePositionInformation implements FileQueryableInformation { 19 | 20 | private long currentByteOffset; 21 | 22 | FilePositionInformation(long currentByteOffset) { 23 | this.currentByteOffset = currentByteOffset; 24 | } 25 | 26 | public long getCurrentByteOffset() { 27 | return currentByteOffset; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileQueryableInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public interface FileQueryableInformation extends FileInformation { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileRenameInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileRenameInformation implements FileSettableInformation { 19 | 20 | private final boolean replaceIfExists; 21 | private final long rootDirectory; // file handle of root directory 22 | private final int fileNameLength; 23 | private final String fileName; 24 | 25 | public FileRenameInformation(boolean replaceIfExists, long rootDirectory, String fileName) { 26 | this.replaceIfExists = replaceIfExists; 27 | this.rootDirectory = rootDirectory; 28 | this.fileNameLength = fileName.length(); 29 | this.fileName = fileName; 30 | } 31 | 32 | public boolean isReplaceIfExists() { 33 | return replaceIfExists; 34 | } 35 | 36 | public long getRootDirectory() { 37 | return rootDirectory; 38 | } 39 | 40 | public int getFileNameLength() { 41 | return fileNameLength; 42 | } 43 | 44 | public String getFileName() { 45 | return fileName; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileSettableInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public interface FileSettableInformation extends FileInformation { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileStreamInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | 22 | public class FileStreamInformation implements FileQueryableInformation { 23 | 24 | private List streamList; 25 | 26 | FileStreamInformation(List streamList) { 27 | this.streamList = streamList; 28 | } 29 | 30 | public List getStreamList() { 31 | return streamList; 32 | } 33 | 34 | public List getStreamNames() { 35 | List nameList = new ArrayList<>(); 36 | for (FileStreamInformationItem s : streamList) { 37 | nameList.add(s.getName()); 38 | } 39 | return nameList; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/msfscc/fileinformation/FileStreamInformationItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msfscc.fileinformation; 17 | 18 | public class FileStreamInformationItem { 19 | 20 | private long size; 21 | private long allocSize; 22 | private String name; 23 | 24 | public FileStreamInformationItem(long size, long allocSize, String name) { 25 | this.size = size; 26 | this.allocSize = allocSize; 27 | this.name = name; 28 | } 29 | 30 | public long getSize() { 31 | return size; 32 | } 33 | 34 | public long getAllocSize() { 35 | return allocSize; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb/SMB1NotSupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb; 17 | 18 | import com.hierynomus.protocol.transport.TransportException; 19 | 20 | @SuppressWarnings("serial") 21 | public class SMB1NotSupportedException extends TransportException { 22 | public SMB1NotSupportedException() { 23 | super("SMBv1 is not supported by SMBJ"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb/SMB1Packet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.smb.SMBBuffer; 20 | import com.hierynomus.smb.SMBPacket; 21 | 22 | public class SMB1Packet extends SMBPacket { 23 | protected SMB1Packet() { 24 | super(new SMB1Header()); 25 | } 26 | 27 | @Override 28 | public final void write(SMBBuffer buffer) { 29 | this.buffer = buffer; 30 | header.writeTo(buffer); 31 | writeTo(buffer); 32 | } 33 | 34 | 35 | /** 36 | * Write the message fields into the buffer, as specified in the MS-SMB specification. 37 | * 38 | * @param buffer 39 | */ 40 | protected void writeTo(SMBBuffer buffer) { 41 | throw new UnsupportedOperationException("Sending SMBv1 messages not supported in SMBJ"); 42 | } 43 | 44 | @Override 45 | protected void read(SMB1PacketData packetData) throws Buffer.BufferException { 46 | throw new UnsupportedOperationException("Receiving SMBv1 messages not supported in SMBJ"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb/SMB1PacketData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.smb.SMBPacketData; 20 | 21 | public class SMB1PacketData extends SMBPacketData { 22 | public SMB1PacketData(byte[] data) throws Buffer.BufferException { 23 | super(new SMB1Header(), data); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb/SMB1PacketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.transport.PacketFactory; 20 | 21 | import java.io.IOException; 22 | 23 | public class SMB1PacketFactory implements PacketFactory { 24 | @Override 25 | public SMB1PacketData read(byte[] data) throws Buffer.BufferException, IOException { 26 | throw new SMB1NotSupportedException(); 27 | } 28 | 29 | @Override 30 | public boolean canHandle(byte[] data) { 31 | return data.length >= 4 && data[0] == (byte) 0xFF && data[1] == 'S' && data[2] == 'M' && data[3] == 'B'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/DeadLetterPacketData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.smb.SMBHeader; 19 | import com.hierynomus.smb.SMBPacketData; 20 | 21 | /** 22 | * Ignore this packet... 23 | */ 24 | public class DeadLetterPacketData extends SMBPacketData { 25 | public DeadLetterPacketData(SMBHeader header) { 26 | super(header); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2ChangeNotifyFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | public enum SMB2ChangeNotifyFlags implements EnumWithValue { 21 | WATCH_TREE(0x0001); 22 | 23 | private long value; 24 | 25 | SMB2ChangeNotifyFlags(long value) { 26 | this.value = value; 27 | } 28 | 29 | public long getValue() { 30 | return value; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2CompletionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * SMB2 Change Notify 2.2.35 - CompletionFilter 22 | */ 23 | public enum SMB2CompletionFilter implements EnumWithValue { 24 | FILE_NOTIFY_CHANGE_FILE_NAME(0x00000001L), 25 | FILE_NOTIFY_CHANGE_DIR_NAME(0x00000002L), 26 | FILE_NOTIFY_CHANGE_ATTRIBUTES(0x00000004L), 27 | FILE_NOTIFY_CHANGE_SIZE(0x00000008L), 28 | FILE_NOTIFY_CHANGE_LAST_WRITE(0x00000010L), 29 | FILE_NOTIFY_CHANGE_LAST_ACCESS(0x00000020L), 30 | FILE_NOTIFY_CHANGE_CREATION(0x00000040L), 31 | FILE_NOTIFY_CHANGE_EA(0x00000080L), 32 | FILE_NOTIFY_CHANGE_SECURITY(0x00000100L), 33 | FILE_NOTIFY_CHANGE_STREAM_NAME(0x00000200L), 34 | FILE_NOTIFY_CHANGE_STREAM_SIZE(0x00000400L), 35 | FILE_NOTIFY_CHANGE_STREAM_WRITE(0x00000800L); 36 | 37 | private long value; 38 | 39 | SMB2CompletionFilter(long value) { 40 | this.value = value; 41 | } 42 | 43 | public long getValue() { 44 | return value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2CreateAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-SMB2].pdf 2.2.14 SMB2 CREATE Response- CreateAction 22 | *

23 | * The action taken in establishing the open. This field MUST contain one of 24 | * the following values. 25 | */ 26 | public enum SMB2CreateAction implements EnumWithValue { 27 | 28 | /** 29 | * An existing file was deleted and a new file was created in its place. 30 | */ 31 | FILE_SUPERSEDED(0x00000000L), 32 | /** 33 | * An existing file was opened. 34 | */ 35 | FILE_OPENED(0x00000001L), 36 | /** 37 | * A new file was created. 38 | */ 39 | FILE_CREATED(0x00000002L), 40 | /** 41 | * An existing file was overwritten 42 | */ 43 | FILE_OVERWRITTEN(0x00000003L); 44 | 45 | private long value; 46 | 47 | SMB2CreateAction(long value) { 48 | this.value = value; 49 | } 50 | 51 | public long getValue() { 52 | return value; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2DecryptedPacketData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.smb.SMBBuffer; 20 | 21 | /** 22 | * PacketData class that indicates this PacketData was instantiated in the PacketEncryptor as part of the 23 | * decryption. 24 | */ 25 | public class SMB2DecryptedPacketData extends SMB2PacketData { 26 | public SMB2DecryptedPacketData(byte[] data) throws Buffer.BufferException { 27 | super(data); 28 | } 29 | 30 | public SMB2DecryptedPacketData(SMBBuffer dataBuffer) throws Buffer.BufferException { 31 | super(dataBuffer); 32 | } 33 | 34 | 35 | public SMB2PacketData next() throws Buffer.BufferException { 36 | if (isCompounded()) { 37 | return new SMB2DecryptedPacketData(dataBuffer); 38 | } else { 39 | return null; 40 | } 41 | } 42 | 43 | public boolean isDecrypted() { 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2Functions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.Charsets; 19 | 20 | public class SMB2Functions { 21 | private static final byte[] EMPTY_BYTES = new byte[0]; 22 | 23 | public static byte[] unicode(String s) { 24 | if (s == null) { 25 | return EMPTY_BYTES; 26 | } else { 27 | return s.getBytes(Charsets.UTF_16LE); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2GlobalCapability.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-SMB2].pdf 2.2.3 SMB2 NEGOTIATE Request - Capabilities 22 | */ 23 | public enum SMB2GlobalCapability implements EnumWithValue { 24 | SMB2_GLOBAL_CAP_DFS(0x01L), 25 | SMB2_GLOBAL_CAP_LEASING(0x02L), 26 | SMB2_GLOBAL_CAP_LARGE_MTU(0x04L), // Multi-Credit support 27 | SMB2_GLOBAL_CAP_MULTI_CHANNEL(0x08L), 28 | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES(0x10L), 29 | SMB2_GLOBAL_CAP_DIRECTORY_LEASING(0x20L), 30 | SMB2_GLOBAL_CAP_ENCRYPTION(0x40L); 31 | 32 | private long i; 33 | 34 | SMB2GlobalCapability(long i) { 35 | this.i = i; 36 | } 37 | 38 | public long getValue() { 39 | return i; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2ImpersonationLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-SMB2] 2.2.13 / [MS-WPO] 9.7 22 | */ 23 | public enum SMB2ImpersonationLevel implements EnumWithValue { 24 | Anonymous(0x00L), 25 | Identification(0x01L), 26 | Impersonation(0x02L), 27 | Delegate(0x03L); 28 | 29 | private long value; 30 | 31 | SMB2ImpersonationLevel(long value) { 32 | this.value = value; 33 | } 34 | 35 | @Override 36 | public long getValue() { 37 | return value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2LockFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-SMB2].pdf 2.2.26.1 SMB2_LOCK_ELEMENT Structure - Flags 22 | */ 23 | public enum SMB2LockFlag implements EnumWithValue { 24 | SMB2_LOCKFLAG_SHARED_LOCK(0x01L), 25 | SMB2_LOCKFLAG_EXCLUSIVE_LOCK(0x02L), 26 | SMB2_LOCKFLAG_UNLOCK(0x04L), 27 | SMB2_LOCKFLAG_FAIL_IMMEDIATELY(0x10L); 28 | 29 | private long value; 30 | 31 | SMB2LockFlag(long value) { 32 | this.value = value; 33 | } 34 | 35 | @Override 36 | public long getValue() { 37 | return value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2MessageFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | public enum SMB2MessageFlag implements EnumWithValue { 21 | SMB2_FLAGS_SERVER_TO_REDIR(0x00000001), 22 | SMB2_FLAGS_ASYNC_COMMAND(0x00000002), 23 | SMB2_FLAGS_RELATED_OPERATIONS(0x00000004), 24 | SMB2_FLAGS_SIGNED(0x00000008), 25 | SMB2_FLAGS_PRIORITY_MASK(0x00000070), 26 | SMB2_FLAGS_DFS_OPERATIONS(0x10000000), 27 | SMB2_FLAGS_REPLAY_OPERATION(0x20000000); 28 | 29 | private long value; 30 | 31 | SMB2MessageFlag(long value) { 32 | this.value = value; 33 | } 34 | 35 | public long getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2MultiCreditPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | public class SMB2MultiCreditPacket extends SMB2Packet { 19 | 20 | private int maxPayloadSize; 21 | 22 | public SMB2MultiCreditPacket(int structureSize, SMB2Dialect dialect, SMB2MessageCommandCode messageType, long sessionId, long treeId, int maxPayloadSize) { 23 | super(structureSize, dialect, messageType, sessionId, treeId); 24 | this.maxPayloadSize = maxPayloadSize; 25 | } 26 | 27 | @Override 28 | public int getMaxPayloadSize() { 29 | return this.maxPayloadSize; 30 | } 31 | 32 | protected int getPayloadSize() { 33 | return Math.min(maxPayloadSize, SINGLE_CREDIT_PAYLOAD_SIZE * getCreditsAssigned()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2PacketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.transport.PacketFactory; 20 | 21 | public class SMB2PacketFactory implements PacketFactory { 22 | 23 | @Override 24 | public SMB2PacketData read(byte[] data) throws Buffer.BufferException { 25 | return new SMB2PacketData(data); 26 | } 27 | 28 | @Override 29 | public boolean canHandle(byte[] data) { 30 | return data.length >= 4 && data[0] == (byte) 0xFE && data[1] == 'S' && data[2] == 'M' && data[3] == 'B'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2ShareAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | import java.util.Collections; 21 | import java.util.EnumSet; 22 | import java.util.Set; 23 | 24 | /** 25 | * SMB2 Create 2.2.13 - SMB2ShareAccess 26 | */ 27 | public enum SMB2ShareAccess implements EnumWithValue { 28 | FILE_SHARE_READ(0x00000001L), 29 | FILE_SHARE_WRITE(0x00000002L), 30 | FILE_SHARE_DELETE(0x00000004L); 31 | 32 | public static final Set ALL = Collections.unmodifiableSet(EnumSet.allOf(SMB2ShareAccess.class)); 33 | 34 | private long value; 35 | 36 | SMB2ShareAccess(long value) { 37 | this.value = value; 38 | } 39 | 40 | public long getValue() { 41 | return value; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB2ShareCapabilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-SMB2].pdf 2.2.10 TREE_CONNECT Response Capabilities 22 | */ 23 | public enum SMB2ShareCapabilities implements EnumWithValue { 24 | SMB2_SHARE_CAP_DFS(0x08L), 25 | SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY(0x10L), 26 | SMB2_SHARE_CAP_SCALEOUT(0x20L), 27 | SMB2_SHARE_CAP_CLUSTER(0x40L), 28 | SMB2_SHARE_CAP_ASYMMETRIC(0x80L); 29 | 30 | private long value; 31 | 32 | SMB2ShareCapabilities(long value) { 33 | this.value = value; 34 | } 35 | 36 | @Override 37 | public long getValue() { 38 | return value; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3CompressedPacketData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.smb.SMBPacketData; 20 | 21 | public class SMB3CompressedPacketData extends SMBPacketData { 22 | private boolean decrypted; 23 | 24 | public SMB3CompressedPacketData(byte[] data) throws Buffer.BufferException { 25 | this(data, false); 26 | } 27 | 28 | public SMB3CompressedPacketData(byte[] data, boolean decrypted) throws Buffer.BufferException { 29 | super(new SMB2CompressionTransformHeader(), data); 30 | this.decrypted = decrypted; 31 | } 32 | 33 | public boolean isDecrypted() { 34 | return decrypted; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3CompressedPacketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.transport.PacketFactory; 20 | 21 | import java.io.IOException; 22 | 23 | public class SMB3CompressedPacketFactory implements PacketFactory { 24 | @Override 25 | public SMB3CompressedPacketData read(byte[] data) throws Buffer.BufferException, IOException { 26 | return new SMB3CompressedPacketData(data); 27 | } 28 | 29 | @Override 30 | public boolean canHandle(byte[] data) { 31 | return data.length >= 4 && data[0] == (byte) 0xFC && data[1] == 'S' && data[2] == 'M' && data[3] == 'B'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3CompressionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | public enum SMB3CompressionAlgorithm implements EnumWithValue { 21 | NONE(0x0000), 22 | LZNT1(0x0001), 23 | LZ77(0x0002), 24 | LZ77_HUFFMAN(0x0003); 25 | 26 | private long value; 27 | 28 | SMB3CompressionAlgorithm(long value) { 29 | this.value = value; 30 | } 31 | 32 | @Override 33 | public long getValue() { 34 | return value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3EncryptedPacketData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.smb.SMBPacketData; 20 | 21 | public class SMB3EncryptedPacketData extends SMBPacketData { 22 | public SMB3EncryptedPacketData(byte[] data) throws Buffer.BufferException { 23 | super(new SMB2TransformHeader(), data); 24 | } 25 | 26 | public byte[] getCipherText() throws Buffer.BufferException { 27 | return getDataBuffer().readRawBytes(getHeader().getOriginalMessageSize()); 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "Encrypted for session id << " + getHeader().getSessionId() + " >>"; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3EncryptedPacketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.transport.PacketFactory; 20 | 21 | import java.io.IOException; 22 | 23 | public class SMB3EncryptedPacketFactory implements PacketFactory { 24 | @Override 25 | public SMB3EncryptedPacketData read(byte[] data) throws Buffer.BufferException, IOException { 26 | return new SMB3EncryptedPacketData(data); 27 | } 28 | 29 | @Override 30 | public boolean canHandle(byte[] data) { 31 | return data.length >= 4 && data[0] == (byte) 0xFD && data[1] == 'S' && data[2] == 'M' && data[3] == 'B'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3EncryptionCipher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /*** 21 | * [MS-SMB2].pdf 2.2.3.1.2 SMB2_ENCRYPTION_CAPABILITIES -- Cipher 22 | */ 23 | public enum SMB3EncryptionCipher implements EnumWithValue { 24 | AES_128_CCM(0x00000001L, "AES/CCM/NoPadding", 11), 25 | AES_128_GCM(0x00000002L, "AES/GCM/NoPadding", 12); 26 | 27 | private long value; 28 | private String algorithmName; 29 | private int nonceLength; 30 | 31 | SMB3EncryptionCipher(long value, String algorithmName, int nonceLength) { 32 | this.value = value; 33 | this.algorithmName = algorithmName; 34 | this.nonceLength = nonceLength; 35 | } 36 | 37 | public long getValue() { 38 | return value; 39 | } 40 | 41 | public String getAlgorithmName() { 42 | return algorithmName; 43 | } 44 | 45 | public int getNonceLength() { 46 | return nonceLength; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/SMB3HashAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /*** 21 | * [MS-SMB2].pdf 2.2.3.1.1 SMB2_PREAUTH_INTEGRITY_CAPABILITIES -- HashAlgorithm 22 | * 23 | * This is part of the SMB3x dialects 24 | */ 25 | public enum SMB3HashAlgorithm implements EnumWithValue { 26 | SHA_512(0x00000001L, "SHA-512"); 27 | 28 | private long value; 29 | private String algorithmName; 30 | 31 | SMB3HashAlgorithm(long value, String algorithmName) { 32 | this.value = value; 33 | this.algorithmName = algorithmName; 34 | } 35 | 36 | public long getValue() { 37 | return value; 38 | } 39 | 40 | public String getAlgorithmName() { 41 | return algorithmName; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/SMB2Echo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages; 17 | 18 | import com.hierynomus.mssmb2.SMB2Dialect; 19 | import com.hierynomus.mssmb2.SMB2MessageCommandCode; 20 | import com.hierynomus.mssmb2.SMB2Packet; 21 | import com.hierynomus.protocol.commons.buffer.Buffer; 22 | import com.hierynomus.smb.SMBBuffer; 23 | 24 | /** 25 | * [MS-SMB2].pdf 2.2.28 SMB2 ECHO Request 26 | */ 27 | public class SMB2Echo extends SMB2Packet { 28 | 29 | public SMB2Echo() { 30 | super(); 31 | } 32 | 33 | public SMB2Echo(SMB2Dialect dialect) { 34 | super(4, dialect, SMB2MessageCommandCode.SMB2_ECHO); 35 | } 36 | 37 | @Override 38 | protected void writeTo(SMBBuffer buffer) { 39 | buffer.putUInt16(structureSize); // StructureSize (2 bytes) 40 | buffer.putUInt16(0); // Reserved 41 | } 42 | 43 | @Override 44 | protected void readMessage(SMBBuffer buffer) throws Buffer.BufferException { 45 | buffer.skip(4); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/SMB2LockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages; 17 | 18 | import com.hierynomus.mssmb2.SMB2Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | import com.hierynomus.smb.SMBBuffer; 21 | 22 | /** 23 | * [MS-SMB2].pdf 2.2.27 SMB2 LOCK Response 24 | * 25 | */ 26 | public class SMB2LockResponse extends SMB2Packet { 27 | @Override 28 | protected void readMessage(SMBBuffer buffer) throws Buffer.BufferException { 29 | buffer.skip(4); // StructureSize (2 bytes) and Reserved (2 bytes) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/SMB2QueryDirectoryResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages; 17 | 18 | import com.hierynomus.mssmb2.SMB2Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | import com.hierynomus.smb.SMBBuffer; 21 | 22 | /** 23 | * [MS-SMB2].pdf 2.2.34 SMB2 QUERY_DIRECTORY Response 24 | */ 25 | public class SMB2QueryDirectoryResponse extends SMB2Packet { 26 | 27 | private byte[] outputBuffer; 28 | 29 | @Override 30 | protected void readMessage(SMBBuffer buffer) throws Buffer.BufferException { 31 | buffer.skip(2); // StructureSize (2 bytes) 32 | int outputBufferOffset = buffer.readUInt16(); // OutputBufferOffset (2 bytes) 33 | int outBufferLength = buffer.readUInt32AsInt(); // OutputBufferLength (4 bytes) 34 | if (outputBufferOffset > 0) { 35 | buffer.rpos(outputBufferOffset); 36 | outputBuffer = buffer.readRawBytes(outBufferLength); 37 | } 38 | } 39 | 40 | public byte[] getOutputBuffer() { 41 | return outputBuffer; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/SMB2QueryInfoResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages; 17 | 18 | import com.hierynomus.mssmb2.SMB2Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | import com.hierynomus.smb.SMBBuffer; 21 | 22 | /** 23 | * [MS-SMB2].pdf 2.2.38 SMB2 QUERY_INFO Response 24 | *

25 | * \ 26 | */ 27 | public class SMB2QueryInfoResponse extends SMB2Packet { 28 | 29 | byte[] outputBuffer; 30 | 31 | @Override 32 | protected void readMessage(SMBBuffer buffer) throws Buffer.BufferException { 33 | buffer.skip(2); // StructureSize (2 bytes) 34 | int outputBufferOffset = buffer.readUInt16(); // OutputBufferOffset (2 bytes) 35 | int outBufferLength = buffer.readUInt32AsInt(); // OutputBufferLength (4 bytes) 36 | buffer.rpos(outputBufferOffset); 37 | outputBuffer = buffer.readRawBytes(outBufferLength); // Buffer (variable) 38 | } 39 | 40 | public byte[] getOutputBuffer() { 41 | return outputBuffer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/SMB2SetInfoResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages; 17 | 18 | import com.hierynomus.mssmb2.SMB2Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | import com.hierynomus.smb.SMBBuffer; 21 | 22 | /** 23 | * [MS-SMB2].pdf 2.2.40 SMB2 SET_INFO Response 24 | */ 25 | public class SMB2SetInfoResponse extends SMB2Packet { 26 | 27 | @Override 28 | protected void readMessage(SMBBuffer buffer) throws Buffer.BufferException { 29 | buffer.skip(2); // StructureSize (2 bytes) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/SMB2WriteResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages; 17 | 18 | import com.hierynomus.mssmb2.SMB2Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | import com.hierynomus.smb.SMBBuffer; 21 | 22 | /** 23 | * [MS-SMB2].pdf 2.2.22 SMB2 Write Response 24 | */ 25 | public class SMB2WriteResponse extends SMB2Packet { 26 | 27 | private int bytesWritten; 28 | 29 | @Override 30 | protected void readMessage(SMBBuffer buffer) throws Buffer.BufferException { 31 | buffer.skip(2); // StructureSize (2 bytes) 32 | buffer.skip(2); // Reserved (2 bytes) 33 | bytesWritten = buffer.readUInt32AsInt(); // Count (4 bytes) 34 | buffer.skip(4); // Remaining (4 bytes) - Reserved do not use 35 | buffer.skip(2); // WriteChannelInfoOffset (2 bytes) - Reserved do not use 36 | buffer.skip(2); // WriteChannelInfoLength (2 bytes) - Reserved do not use 37 | } 38 | 39 | public int getBytesWritten() { 40 | return bytesWritten; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/mssmb2/messages/negotiate/SMB2NegotiateContextType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages.negotiate; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | /** 21 | * [MS-SMB2] 2.2.3.1 SMB2 NEGOTIATE_CONTEXT Request values - ContextType 22 | */ 23 | public enum SMB2NegotiateContextType implements EnumWithValue { 24 | SMB2_PREAUTH_INTEGRITY_CAPABILITIES(0x00000001L), 25 | SMB2_ENCRYPTION_CAPABILITIES(0x00000002L), 26 | SMB2_COMPRESSION_CAPABILITIES(0x00000004L), 27 | SMB2_NETNAME_NEGOTIATE_CONTEXT_ID(0x00000005L); 28 | 29 | private long value; 30 | 31 | SMB2NegotiateContextType(long value) { 32 | this.value = value; 33 | } 34 | 35 | public long getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/NtlmException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm; 17 | 18 | @SuppressWarnings("serial") 19 | public class NtlmException extends RuntimeException { 20 | 21 | public NtlmException() { 22 | super(); 23 | } 24 | 25 | public NtlmException(String message) { 26 | super(message); 27 | } 28 | 29 | public NtlmException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public NtlmException(Throwable cause) { 34 | super(cause); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue; 19 | 20 | public enum AvId implements EnumWithValue { 21 | MsvAvEOL(0x00L), 22 | MsvAvNbComputerName(0x01L), 23 | MsvAvNbDomainName(0x02L), 24 | MsvAvDnsComputerName(0x03L), 25 | MsvAvDnsDomainName(0x04L), 26 | MsvAvDnsTreeName(0x05L), 27 | MsvAvFlags(0x06L), 28 | MsvAvTimestamp(0x07L), 29 | MsvAvSingleHost(0x08L), 30 | MsvAvTargetName(0x09L), 31 | MsvAvChannelBindings(0x0AL); 32 | 33 | private final long value; 34 | 35 | AvId(long i) { 36 | this.value = i; 37 | } 38 | 39 | @Override 40 | public long getValue() { 41 | return value; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvPair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | 20 | public abstract class AvPair { 21 | 22 | protected AvId avId; 23 | protected T value; 24 | 25 | public AvPair(AvId avId) { 26 | this.avId = avId; 27 | } 28 | 29 | public AvPair(AvId avId, T value) { 30 | this.avId = avId; 31 | this.value = value; 32 | } 33 | 34 | public abstract void write(Buffer buffer); 35 | 36 | public abstract AvPair read(Buffer buffer) throws Buffer.BufferException; 37 | 38 | public AvId getAvId() { 39 | return avId; 40 | } 41 | 42 | public T getValue() { 43 | return value; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "AvPair{" + 49 | "avId=" + avId.name() + 50 | ", value=" + value + 51 | '}'; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvPairChannelBindings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.commons.buffer.Buffer.BufferException; 20 | 21 | public class AvPairChannelBindings extends AvPair { 22 | 23 | AvPairChannelBindings() { 24 | super(AvId.MsvAvChannelBindings); 25 | } 26 | 27 | public AvPairChannelBindings(byte[] value) { 28 | super(AvId.MsvAvChannelBindings, value); 29 | } 30 | 31 | @Override 32 | public void write(Buffer buffer) { 33 | buffer.putUInt16((int) this.avId.getValue()); // AvId (2 bytes) 34 | buffer.putUInt16(value.length); // AvLen (2 bytes) 35 | buffer.putRawBytes(value); // Value (AvLen bytes) 36 | } 37 | 38 | @Override 39 | public AvPair read(Buffer buffer) throws BufferException { 40 | int length = buffer.readUInt16(); // AvLen (2 bytes) 41 | this.value = buffer.readRawBytes(length); // Value (AvLen bytes) 42 | return this; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvPairEnd.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.commons.buffer.Buffer.BufferException; 20 | 21 | public class AvPairEnd extends AvPair { 22 | 23 | public AvPairEnd() { 24 | super(AvId.MsvAvEOL); 25 | } 26 | 27 | @Override 28 | public void write(Buffer buffer) { 29 | buffer.putUInt16((int) this.avId.getValue()); // AvId (2 bytes) 30 | buffer.putUInt16(0); // AvLen (2 bytes) 31 | } 32 | 33 | @Override 34 | public AvPair read(Buffer buffer) throws BufferException { 35 | buffer.readUInt16(); // AvLen (2 bytes) 36 | return this; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvPairFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.protocol.commons.buffer.Buffer.BufferException; 20 | 21 | public class AvPairFlags extends AvPair { 22 | 23 | AvPairFlags() { 24 | super(AvId.MsvAvFlags); 25 | } 26 | 27 | public AvPairFlags(long value) { 28 | super(AvId.MsvAvFlags, value); 29 | } 30 | 31 | @Override 32 | public void write(Buffer buffer) { 33 | buffer.putUInt16((int) this.avId.getValue()); // AvId (2 bytes) 34 | buffer.putUInt16(4); // AvLen (2 bytes) 35 | buffer.putUInt32(this.value); // Value (AvLen bytes) 36 | } 37 | 38 | @Override 39 | public AvPair read(Buffer buffer) throws BufferException { 40 | buffer.readUInt16(); // AvLen (2 bytes) 41 | this.value = buffer.readUInt32(); // Value (AvLen bytes) 42 | return this; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvPairString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.protocol.commons.Charsets; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | import com.hierynomus.protocol.commons.buffer.Buffer.BufferException; 21 | 22 | public class AvPairString extends AvPair { 23 | 24 | AvPairString(AvId avId) { 25 | super(avId); 26 | } 27 | 28 | public AvPairString(AvId avId, String value) { 29 | super(avId, value); 30 | } 31 | 32 | @Override 33 | public AvPairString read(Buffer buffer) throws BufferException { 34 | int avLen = buffer.readUInt16(); // AvLen (2 bytes) 35 | this.value = buffer.readString(Charsets.UTF_16LE, avLen / 2); // Value (AvLen bytes) 36 | return this; 37 | } 38 | 39 | @Override 40 | public void write(Buffer buffer) { 41 | buffer.putUInt16((int) this.avId.getValue()); // AvId (2 bytes) 42 | buffer.putUInt16(this.value.length() * 2); // AvLen (2 bytes) 43 | buffer.putString(this.value, Charsets.UTF_16LE); // Value (AvLen bytes) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/av/AvPairTimestamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.av; 17 | 18 | import com.hierynomus.msdtyp.FileTime; 19 | import com.hierynomus.msdtyp.MsDataTypes; 20 | import com.hierynomus.protocol.commons.buffer.Buffer; 21 | import com.hierynomus.protocol.commons.buffer.Buffer.BufferException; 22 | 23 | public class AvPairTimestamp extends AvPair { 24 | 25 | AvPairTimestamp() { 26 | super(AvId.MsvAvTimestamp); 27 | } 28 | 29 | @Override 30 | public void write(Buffer buffer) { 31 | buffer.putUInt16((int) this.avId.getValue()); // AvId (2 bytes) 32 | buffer.putUInt16(8); // AvLen (2 bytes) 33 | MsDataTypes.putFileTime(value, buffer); // Value (AvLen bytes) 34 | } 35 | 36 | @Override 37 | public AvPair read(Buffer buffer) throws BufferException { 38 | buffer.readUInt16(); // AvLen (2 bytes) 39 | this.value = MsDataTypes.readFileTime(buffer); // Value (AvLen bytes) 40 | return this; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/functions/ComputedNtlmV2Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.functions; 17 | 18 | public class ComputedNtlmV2Response { 19 | private byte[] ntResponse; 20 | private byte[] lmResponse; 21 | private byte[] sessionBaseKey; 22 | 23 | public ComputedNtlmV2Response(byte[] ntResponse, byte[] lmResponse, byte[] sessionBaseKey) { 24 | this.ntResponse = ntResponse; 25 | this.lmResponse = lmResponse; 26 | this.sessionBaseKey = sessionBaseKey; 27 | } 28 | 29 | public byte[] getNtResponse() { 30 | return ntResponse; 31 | } 32 | 33 | public byte[] getLmResponse() { 34 | return lmResponse; 35 | } 36 | 37 | public byte[] getSessionBaseKey() { 38 | return sessionBaseKey; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/messages/NtlmMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.messages; 17 | 18 | import java.util.EnumSet; 19 | import java.util.Set; 20 | 21 | import static com.hierynomus.ntlm.messages.NtlmNegotiateFlag.*; 22 | 23 | class NtlmMessage extends NtlmPacket { 24 | protected static Set DEFAULT_FLAGS = EnumSet.of( 25 | NTLMSSP_NEGOTIATE_NTLM, 26 | NTLMSSP_NEGOTIATE_UNICODE); 27 | 28 | protected Set negotiateFlags; 29 | protected WindowsVersion version; 30 | 31 | protected NtlmMessage(Set negotiateFlags, WindowsVersion version) { 32 | this.negotiateFlags = EnumSet.copyOf(negotiateFlags); 33 | this.negotiateFlags.addAll(DEFAULT_FLAGS); 34 | this.version = version; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/messages/NtlmPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.messages; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | 21 | public class NtlmPacket implements Packet { 22 | 23 | @Override 24 | public void write(Buffer.PlainBuffer buffer) { 25 | throw new UnsupportedOperationException("Not implemented by base class"); 26 | } 27 | 28 | @Override 29 | public void read(Buffer.PlainBuffer buffer) throws Buffer.BufferException { 30 | throw new UnsupportedOperationException("Not implemented by base class"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/ntlm/messages/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.ntlm.messages; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | 20 | import static com.hierynomus.ntlm.functions.NtlmFunctions.unicode; 21 | 22 | class Utils { 23 | public static byte[] EMPTY = new byte[0]; 24 | 25 | /** 26 | * Avoid instantiation. 27 | */ 28 | private Utils() {} 29 | 30 | 31 | static int writeOffsettedByteArrayFields(Buffer.PlainBuffer buffer, byte[] bytes, int offset) { 32 | byte[] arr = bytes != null ? bytes : EMPTY; 33 | buffer.putUInt16(arr.length); // ArrayLen (2 bytes) 34 | buffer.putUInt16(arr.length); // ArrayMaxLen (2 bytes) 35 | buffer.putUInt32(offset); // ArrayOffset (4 bytes) 36 | return offset + arr.length; 37 | } 38 | 39 | static byte[] ensureNotNull(byte[] possiblyNull) { 40 | return possiblyNull != null ? possiblyNull : EMPTY; 41 | } 42 | 43 | static byte[] ensureNotNull(String possiblyNull) { 44 | return possiblyNull != null ? unicode(possiblyNull) : EMPTY; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/Packet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | 20 | public interface Packet> { 21 | 22 | void write(B buffer); 23 | 24 | void read(B buffer) throws Buffer.BufferException; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/PacketData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | 20 | /** 21 | * Represents the received (potentially partially deserialized) packet data. 22 | * @param The Buffer type. 23 | */ 24 | public interface PacketData> { 25 | B getDataBuffer(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/commons/Charsets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.commons; 17 | 18 | import java.nio.charset.Charset; 19 | 20 | /** 21 | * Android compatibility layer, as API level 19 does not have {@link java.nio.charset.StandardCharsets}. 22 | */ 23 | public final class Charsets { 24 | public static final Charset UTF_8 = Charset.forName("UTF-8"); 25 | public static final Charset UTF_16BE = Charset.forName("UTF-16BE"); 26 | public static final Charset UTF_16LE = Charset.forName("UTF-16LE"); 27 | public static final Charset UTF_16 = Charset.forName("UTF-16"); 28 | public static final Charset US_ASCII = Charset.forName("US-ASCII"); 29 | 30 | private Charsets() { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/commons/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.commons; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | public class IOUtils { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); 24 | 25 | public static void closeQuietly(AutoCloseable... closeables) { 26 | for (AutoCloseable c : closeables) { 27 | try { 28 | if (c != null) { 29 | c.close(); 30 | } 31 | } catch (Exception logged) { 32 | logger.warn("Error closing {} - {}", c, logged); 33 | } 34 | } 35 | } 36 | 37 | public static void closeSilently(AutoCloseable... closeables) { 38 | for (AutoCloseable c : closeables) { 39 | try { 40 | if (c != null) { 41 | c.close(); 42 | } 43 | } catch (Exception ignored) { 44 | // Dismiss the exception 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/commons/Objects.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.commons; 17 | 18 | import java.util.Arrays; 19 | 20 | public class Objects { 21 | private Objects() { 22 | // Do not instantiate 23 | } 24 | 25 | public static boolean equals(Object a, Object b) { 26 | return (a == b) || (a != null && a.equals(b)); 27 | } 28 | 29 | public static int hash(Object... values) { 30 | return Arrays.hashCode(values); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/commons/backport/JavaVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.commons.backport; 17 | 18 | public class JavaVersion { 19 | public static boolean isJava7OrEarlier() { 20 | String property = System.getProperty("java.specification.version"); 21 | float diff = Float.parseFloat(property) - 1.7f; 22 | 23 | return diff < 0.01; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/commons/concurrent/AFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.commons.concurrent; 17 | 18 | import java.util.concurrent.Future; 19 | 20 | public abstract class AFuture implements Future { 21 | public interface Function { 22 | B apply(A a); 23 | } 24 | 25 | public AFuture map(Function f) { 26 | return new TransformedFuture<>(this, f); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/commons/concurrent/ExceptionWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.commons.concurrent; 17 | 18 | public interface ExceptionWrapper { 19 | 20 | T wrap(Throwable throwable); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Generic protocol layer, unaware of the protocol implemented. 18 | *

19 | * Can later be split off as a library to implement different protocols on. 20 | */ 21 | package com.hierynomus.protocol; 22 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/transport/PacketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.transport; 17 | 18 | import com.hierynomus.protocol.PacketData; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | 21 | import java.io.IOException; 22 | 23 | public interface PacketFactory> { 24 | 25 | /** 26 | * Construct {@link PacketData packet data} out of the raw byte data. 27 | * 28 | * @param data the byte array containing the full packet data 29 | * @return A newly constructed {@link PacketData} object. 30 | */ 31 | D read(byte[] data) throws Buffer.BufferException, IOException; 32 | 33 | /** 34 | * Checks whether this PacketFactory is able to handle the incoming raw byte data. 35 | * 36 | * @param data the byte array containing the full packet data 37 | * @return true if the {@link #read(byte[])} will result in a packet, false otherwise. 38 | */ 39 | boolean canHandle(byte[] data); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/transport/PacketHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.transport; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | import com.hierynomus.protocol.PacketData; 20 | 21 | /** 22 | * Groups together all the various handlers involved in dealing with packets of 23 | * type P. 24 | */ 25 | public class PacketHandlers, P extends Packet> { 26 | private final PacketSerializer serializer; 27 | private final PacketReceiver receiver; 28 | private final PacketFactory packetFactory; 29 | 30 | public PacketHandlers(PacketSerializer serializer, PacketReceiver receiver, PacketFactory packetFactory) { 31 | super(); 32 | this.serializer = serializer; 33 | this.receiver = receiver; 34 | this.packetFactory = packetFactory; 35 | } 36 | 37 | public PacketSerializer getSerializer() { 38 | return serializer; 39 | } 40 | 41 | public PacketReceiver getReceiver() { 42 | return receiver; 43 | } 44 | 45 | public PacketFactory getPacketFactory() { 46 | return packetFactory; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/transport/PacketReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.transport; 17 | 18 | import com.hierynomus.protocol.PacketData; 19 | 20 | public interface PacketReceiver> { 21 | void handle(D packet) throws TransportException; 22 | 23 | void handleError(Throwable t); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/transport/PacketSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.transport; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | 21 | /** 22 | * Serialize a Packet into its wire-format. 23 | * @param

The Packet type 24 | * @param The Buffer type 25 | */ 26 | public interface PacketSerializer

, B extends Buffer> { 27 | 28 | B write(P packet); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/transport/TransportException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.transport; 17 | 18 | import com.hierynomus.protocol.commons.concurrent.ExceptionWrapper; 19 | 20 | import java.io.IOException; 21 | 22 | @SuppressWarnings("serial") 23 | public class TransportException extends IOException { 24 | public static final ExceptionWrapper Wrapper = new ExceptionWrapper() { 25 | @Override 26 | public TransportException wrap(Throwable throwable) { 27 | if (throwable instanceof TransportException) { 28 | return (TransportException) throwable; 29 | } 30 | return new TransportException(throwable); 31 | } 32 | }; 33 | 34 | public TransportException(Throwable ioe) { 35 | super(ioe); 36 | } 37 | 38 | public TransportException(String s) { 39 | super(s); 40 | } 41 | 42 | public TransportException(String s, Throwable throwable) { 43 | super(s, throwable); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/protocol/transport/TransportLayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.protocol.transport; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | 20 | import java.io.IOException; 21 | import java.net.InetSocketAddress; 22 | 23 | public interface TransportLayer

> { 24 | 25 | /** 26 | * Write the packet to the transport. 27 | * 28 | * @param packet The packet to write. 29 | */ 30 | void write(P packet) throws TransportException; 31 | 32 | /** 33 | * Connect to the remote side 34 | * 35 | * @param remoteAddress The remote address to connect to 36 | */ 37 | void connect(InetSocketAddress remoteAddress) throws IOException; 38 | 39 | /** 40 | * Disconnect from the remote side 41 | * 42 | * @throws IOException 43 | */ 44 | void disconnect() throws IOException; 45 | 46 | /** 47 | * Checks if the transport layer is currently connected. 48 | */ 49 | boolean isConnected(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/AEADBlockCipher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | import javax.crypto.spec.GCMParameterSpec; 19 | 20 | public interface AEADBlockCipher { 21 | 22 | void init(Cipher.CryptMode cryptMode, byte[] bytes, GCMParameterSpec gcmParameterSpec) throws SecurityException; 23 | 24 | void updateAAD(byte[] aad, int aadOffset, int aadLength) throws SecurityException; 25 | 26 | byte[] update(byte[] in, int inOffset, int inLength) throws SecurityException; 27 | 28 | byte[] doFinal(byte[] in, int inOffset, int inLength) throws SecurityException; 29 | 30 | void reset(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/Cipher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | public interface Cipher { 19 | enum CryptMode {ENCRYPT, DECRYPT} 20 | 21 | void init(CryptMode cryptMode, byte[] bytes) throws SecurityException; 22 | 23 | int update(byte[] in, int inOff, int bytes, byte[] out, int outOff) throws SecurityException; 24 | 25 | int doFinal(byte[] out, int outOff) throws SecurityException; 26 | 27 | void reset(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/DerivationFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | import com.hierynomus.security.jce.derivationfunction.DerivationParameters; 19 | 20 | public interface DerivationFunction { 21 | 22 | void init(DerivationParameters parameters) throws SecurityException; 23 | 24 | int generateBytes(byte[] out, int outOff, int len); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/Mac.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | public interface Mac { 19 | void init(byte[] key) throws SecurityException; 20 | 21 | void update(byte b); 22 | 23 | void update(byte[] array); 24 | 25 | void update(byte[] array, int offset, int length); 26 | 27 | byte[] doFinal(); 28 | 29 | void reset(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/MessageDigest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | public interface MessageDigest { 19 | void update(byte b); 20 | 21 | void update(byte[] bytes); 22 | 23 | void update(byte[] bytes, int offset, int len); 24 | 25 | byte[] digest(); 26 | 27 | void reset(); 28 | 29 | int getDigestLength(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/SecurityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | @SuppressWarnings("serial") 19 | public class SecurityException extends Exception { 20 | public SecurityException(String message) { 21 | super(message); 22 | } 23 | 24 | public SecurityException(Exception e) { 25 | super(e); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/SecurityProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security; 17 | 18 | /** 19 | * Abstraction layer over different Security Providers. 20 | *

21 | * Using this you can easily choose to either use: 22 | *

23 | * - Standard JCE 24 | * - BouncyCastle over JCE 25 | * - BouncyCastle direct 26 | *

27 | * The advantage of using BouncyCastle directly is that you do not need to have the JCE 28 | * Unlimited Strength Cryptography policy files loaded in your JRE. 29 | */ 30 | public interface SecurityProvider { 31 | MessageDigest getDigest(String name) throws SecurityException; 32 | 33 | Mac getMac(String name) throws SecurityException; 34 | 35 | Cipher getCipher(String name) throws SecurityException; 36 | 37 | AEADBlockCipher getAEADBlockCipher(String name) throws SecurityException; 38 | 39 | DerivationFunction getDerivationFunction(String name) throws SecurityException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/jce/JceDerivationFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security.jce; 17 | 18 | import com.hierynomus.security.DerivationFunction; 19 | import com.hierynomus.security.SecurityException; 20 | import com.hierynomus.security.jce.derivationfunction.DerivationParameters; 21 | 22 | public class JceDerivationFunction implements DerivationFunction { 23 | 24 | @Override 25 | public void init(DerivationParameters parameters) throws SecurityException { 26 | throw new UnsupportedOperationException(); 27 | } 28 | 29 | @Override 30 | public int generateBytes(byte[] out, int outOff, int len) { 31 | throw new UnsupportedOperationException(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/security/jce/derivationfunction/DerivationParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security.jce.derivationfunction; 17 | 18 | public interface DerivationParameters { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smb/Packets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smb; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | import com.hierynomus.smbj.common.SMBRuntimeException; 20 | 21 | public class Packets { 22 | /** 23 | * Get the serialized packet bytes. 24 | * 25 | * @param packet The packet to serialize. 26 | * @return The serialized packet bytes. 27 | */ 28 | public static byte[] getPacketBytes(SMBPacket packet) { 29 | SMBBuffer buffer = packet.getBuffer(); 30 | int originalPos = buffer.rpos(); 31 | buffer.rpos(packet.getHeader().getHeaderStartPosition()); 32 | byte[] packetBytes = new byte[packet.getHeader().getMessageEndPosition() - packet.getHeader().getHeaderStartPosition()]; // Allocate large enough byte[] for message 33 | try { 34 | buffer.readRawBytes(packetBytes); 35 | } catch (Buffer.BufferException be) { 36 | throw new SMBRuntimeException("Cannot read packet bytes from buffer", be); 37 | } 38 | buffer.rpos(originalPos); 39 | return packetBytes; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smb/SMBHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smb; 17 | 18 | import com.hierynomus.protocol.commons.buffer.Buffer; 19 | 20 | public interface SMBHeader { 21 | void writeTo(SMBBuffer buffer); 22 | 23 | void readFrom(Buffer buffer) throws Buffer.BufferException; 24 | 25 | int getHeaderStartPosition(); 26 | 27 | int getMessageEndPosition(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smb/SMBPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smb; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | 21 | public abstract class SMBPacket, H extends SMBHeader> implements Packet { 22 | protected H header; 23 | protected SMBBuffer buffer; 24 | 25 | public SMBPacket(H header) { 26 | this.header = header; 27 | } 28 | 29 | public H getHeader() { 30 | return header; 31 | } 32 | 33 | protected abstract void read(D packetData) throws Buffer.BufferException; 34 | 35 | @Override 36 | public final void read(SMBBuffer buffer) throws Buffer.BufferException { 37 | throw new UnsupportedOperationException("Call read(D extends PacketData) instead of this method"); 38 | } 39 | 40 | public SMBBuffer getBuffer() { 41 | return buffer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/ProgressListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj; 17 | 18 | public interface ProgressListener { 19 | 20 | /** 21 | * Invoked when the progress of the API call changes. 22 | * 23 | * @param numBytes the number of bytes completed. 24 | * @param totalBytes the total number of bytes. 25 | */ 26 | void onProgressChanged(long numBytes, long totalBytes); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/auth/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.auth; 17 | 18 | import java.io.IOException; 19 | 20 | import com.hierynomus.smbj.SmbConfig; 21 | import com.hierynomus.smbj.connection.ConnectionContext; 22 | 23 | public interface Authenticator { 24 | 25 | void init(SmbConfig config); 26 | 27 | boolean supports(AuthenticationContext context); 28 | 29 | AuthenticateResponse authenticate(AuthenticationContext context, byte[] gssToken, ConnectionContext connectionContext) throws IOException; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/auth/GSSAuthenticationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.auth; 17 | 18 | import org.ietf.jgss.GSSCredential; 19 | 20 | import javax.security.auth.Subject; 21 | 22 | public class GSSAuthenticationContext extends AuthenticationContext { 23 | Subject subject; 24 | GSSCredential creds; 25 | 26 | public GSSAuthenticationContext(String username, String domain, Subject subject, GSSCredential creds) { 27 | super(username, new char[0], domain); 28 | this.subject = subject; 29 | this.creds = creds; 30 | } 31 | 32 | public Subject getSubject() { 33 | return subject; 34 | } 35 | 36 | public GSSCredential getCreds() { 37 | return creds; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "GSSAuthenticationContext[" + subject + ']'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/common/Check.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.common; 17 | 18 | import java.util.Arrays; 19 | 20 | public class Check { 21 | public static void ensureEquals(byte[] real, byte[] expected, String errorMessage) { 22 | if (!Arrays.equals(real, expected)) { 23 | throw new IllegalArgumentException(errorMessage); 24 | } 25 | } 26 | 27 | public static void ensure(boolean condition, String errorMessage) { 28 | if (!condition) { 29 | throw new IllegalStateException(errorMessage); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/common/Pooled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.common; 17 | 18 | import java.util.concurrent.atomic.AtomicInteger; 19 | 20 | public class Pooled> { 21 | 22 | /** 23 | * A newly created {@link Pooled} object has 1 lease outstanding (the created object) 24 | */ 25 | private final AtomicInteger leases = new AtomicInteger(1); 26 | 27 | /** 28 | * Takes a lease on the pooled object. 29 | * @return this if the object is still valid (has at least 1 lease), else null 30 | */ 31 | @SuppressWarnings("unchecked") 32 | public A lease() { 33 | if (leases.getAndIncrement() > 0) { 34 | return (A) this; 35 | } 36 | return null; 37 | } 38 | 39 | /** 40 | * Releases the pooled object. 41 | * If this was the last outstanding lease, {@link #release()} returns true. 42 | * @return true if this was the last outstanding lease. Else false 43 | */ 44 | public boolean release() { 45 | return leases.decrementAndGet() <= 0; 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/common/SMBException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.common; 17 | 18 | import com.hierynomus.protocol.commons.concurrent.ExceptionWrapper; 19 | 20 | import java.io.IOException; 21 | 22 | @SuppressWarnings("serial") 23 | public class SMBException extends IOException { 24 | public static final ExceptionWrapper Wrapper = new ExceptionWrapper() { 25 | @Override 26 | public SMBException wrap(Throwable throwable) { 27 | if (throwable instanceof SMBException) { 28 | return (SMBException) throwable; 29 | } else { 30 | return new SMBException(throwable); 31 | } 32 | } 33 | }; 34 | 35 | public SMBException(String message) { 36 | super(message); 37 | } 38 | 39 | public SMBException(Throwable t) { 40 | super(t); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/common/SMBRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.common; 17 | 18 | import com.hierynomus.protocol.commons.concurrent.ExceptionWrapper; 19 | 20 | @SuppressWarnings("serial") 21 | public class SMBRuntimeException extends RuntimeException { 22 | public static final ExceptionWrapper Wrapper = new ExceptionWrapper() { 23 | @Override 24 | public SMBRuntimeException wrap(Throwable throwable) { 25 | if (throwable instanceof SMBRuntimeException) { 26 | return (SMBRuntimeException) throwable; 27 | } else { 28 | return new SMBRuntimeException(throwable); 29 | } 30 | } 31 | }; 32 | 33 | public SMBRuntimeException(Throwable t) { 34 | super(t); 35 | } 36 | 37 | public SMBRuntimeException(String msg) { 38 | super(msg); 39 | } 40 | 41 | public SMBRuntimeException(String message, Throwable cause) { 42 | super(message, cause); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/NoSignatory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection; 17 | 18 | import javax.crypto.SecretKey; 19 | 20 | import com.hierynomus.mssmb2.SMB2Packet; 21 | import com.hierynomus.mssmb2.SMB2PacketData; 22 | 23 | /** 24 | * When signing is disabled, this class is used to sign and verify packets so that the code does not need to take the lack of signing into account. 25 | */ 26 | public class NoSignatory implements Signatory { 27 | @Override 28 | public SMB2Packet sign(SMB2Packet packet, SecretKey secretKey) { 29 | return packet; 30 | } 31 | 32 | @Override 33 | public boolean verify(SMB2PacketData packet, SecretKey secretKey) { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/SMBPacketSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection; 17 | 18 | import com.hierynomus.protocol.transport.PacketSerializer; 19 | import com.hierynomus.smb.SMBBuffer; 20 | import com.hierynomus.smb.SMBPacket; 21 | 22 | public class SMBPacketSerializer implements PacketSerializer, SMBBuffer> { 23 | 24 | @Override 25 | public SMBBuffer write(SMBPacket packet) { 26 | SMBBuffer b = new SMBBuffer(); 27 | packet.write(b); 28 | return b; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/Signatory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection; 17 | 18 | import javax.crypto.SecretKey; 19 | 20 | import com.hierynomus.mssmb2.SMB2Packet; 21 | import com.hierynomus.mssmb2.SMB2PacketData; 22 | 23 | public interface Signatory { 24 | public SMB2Packet sign(SMB2Packet packet, SecretKey secretKey); 25 | 26 | public boolean verify(SMB2PacketData packet, SecretKey secretKey); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/packet/AbstractIncomingPacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection.packet; 17 | 18 | import com.hierynomus.protocol.transport.TransportException; 19 | import com.hierynomus.smb.SMBPacketData; 20 | 21 | public abstract class AbstractIncomingPacketHandler implements IncomingPacketHandler { 22 | protected IncomingPacketHandler next; 23 | 24 | @Override 25 | public void handle(SMBPacketData packetData) throws TransportException { 26 | if (canHandle(packetData)) { 27 | doHandle(packetData); 28 | } else { 29 | next.handle(packetData); 30 | } 31 | } 32 | 33 | @Override 34 | public IncomingPacketHandler setNext(IncomingPacketHandler handler) { 35 | this.next = handler; 36 | return this; 37 | } 38 | 39 | protected abstract boolean canHandle(SMBPacketData packetData); 40 | 41 | protected abstract void doHandle(SMBPacketData packetData) throws TransportException; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/packet/DeadLetterPacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection.packet; 17 | 18 | import com.hierynomus.protocol.transport.TransportException; 19 | import com.hierynomus.smb.SMBPacketData; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | public class DeadLetterPacketHandler extends AbstractIncomingPacketHandler { 24 | private static final Logger logger = LoggerFactory.getLogger(DeadLetterPacketHandler.class); 25 | @Override 26 | protected boolean canHandle(SMBPacketData packetData) { 27 | return true; 28 | } 29 | 30 | @Override 31 | protected void doHandle(SMBPacketData packetData) throws TransportException { 32 | logger.warn("Packet << {} >> ended up in dead letters", packetData); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/packet/IncomingPacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection.packet; 17 | 18 | import com.hierynomus.protocol.transport.TransportException; 19 | import com.hierynomus.smb.SMBPacketData; 20 | 21 | public interface IncomingPacketHandler { 22 | 23 | void handle(SMBPacketData packetData) throws TransportException; 24 | 25 | /** 26 | * Adds the given IncomingPacketHandler to the handling chain, and returns it, so that this call can be chained. 27 | * @param handler 28 | * @return The handler that was added to the chain 29 | */ 30 | IncomingPacketHandler setNext(IncomingPacketHandler handler); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/packet/SMB1PacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection.packet; 17 | 18 | import com.hierynomus.mssmb.SMB1NotSupportedException; 19 | import com.hierynomus.mssmb.SMB1PacketData; 20 | import com.hierynomus.protocol.transport.TransportException; 21 | import com.hierynomus.smb.SMBPacketData; 22 | 23 | public class SMB1PacketHandler extends AbstractIncomingPacketHandler { 24 | @Override 25 | public boolean canHandle(SMBPacketData packetData) { 26 | return packetData instanceof SMB1PacketData; 27 | } 28 | 29 | @Override 30 | protected void doHandle(SMBPacketData packetData) throws TransportException { 31 | throw new SMB1NotSupportedException(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/connection/packet/SMB2PacketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.connection.packet; 17 | 18 | 19 | import com.hierynomus.mssmb2.SMB2PacketData; 20 | import com.hierynomus.protocol.transport.TransportException; 21 | import com.hierynomus.smb.SMBPacketData; 22 | 23 | public abstract class SMB2PacketHandler extends AbstractIncomingPacketHandler { 24 | @Override 25 | public boolean canHandle(SMBPacketData packetData) { 26 | return packetData instanceof SMB2PacketData; 27 | } 28 | 29 | @Override 30 | protected void doHandle(SMBPacketData packetData) throws TransportException { 31 | doSMB2Handle((SMB2PacketData) packetData); 32 | } 33 | 34 | protected abstract void doSMB2Handle(SMB2PacketData packetData) throws TransportException; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/event/ConnectionClosed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.event; 17 | 18 | public class ConnectionClosed implements SMBEvent { 19 | private String hostname; 20 | private int port; 21 | 22 | public ConnectionClosed(String hostname, int port) { 23 | this.hostname = hostname; 24 | this.port = port; 25 | } 26 | 27 | public String getHostname() { 28 | return hostname; 29 | } 30 | 31 | public int getPort() { 32 | return port; 33 | } 34 | 35 | @Override 36 | public boolean equals(Object o) { 37 | if (this == o) return true; 38 | if (o == null || getClass() != o.getClass()) return false; 39 | 40 | ConnectionClosed that = (ConnectionClosed) o; 41 | 42 | if (port != that.port) return false; 43 | return hostname.equals(that.hostname); 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | int result = hostname.hashCode(); 49 | result = 31 * result + port; 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/event/SMBEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.event; 17 | 18 | /** 19 | * Base class for SMB events that need to be handled by event handlers (observers) 20 | */ 21 | public interface SMBEvent { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/event/SessionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.event; 17 | 18 | abstract class SessionEvent implements SMBEvent { 19 | private long sessionId; 20 | 21 | public SessionEvent(long sessionId) { 22 | this.sessionId = sessionId; 23 | } 24 | 25 | public long getSessionId() { 26 | return sessionId; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object o) { 31 | if (this == o) return true; 32 | if (o == null || getClass() != o.getClass()) return false; 33 | 34 | SessionEvent that = (SessionEvent) o; 35 | 36 | return sessionId == that.sessionId; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | return (int) (sessionId ^ (sessionId >>> 32)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/event/SessionLoggedOff.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.event; 17 | 18 | public class SessionLoggedOff extends SessionEvent { 19 | 20 | public SessionLoggedOff(long sessionId) { 21 | super(sessionId); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/event/TreeDisconnected.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.event; 17 | 18 | public class TreeDisconnected extends SessionEvent { 19 | 20 | private long treeId; 21 | 22 | public TreeDisconnected(long sessionId, long treeId) { 23 | super(sessionId); 24 | this.treeId = treeId; 25 | } 26 | 27 | public long getTreeId() { 28 | return treeId; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/io/ByteBufferByteChunkProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.io; 17 | 18 | import java.io.IOException; 19 | import java.nio.ByteBuffer; 20 | 21 | public class ByteBufferByteChunkProvider extends CachingByteChunkProvider { 22 | private ByteBuffer buffer; 23 | 24 | public ByteBufferByteChunkProvider(ByteBuffer buffer) { 25 | super(); 26 | this.buffer = buffer; 27 | } 28 | 29 | public ByteBufferByteChunkProvider(ByteBuffer buffer, long fileOffset) { 30 | super(); 31 | this.buffer = buffer; 32 | this.offset = fileOffset; 33 | } 34 | 35 | @Override 36 | int prepareChunk(byte[] chunk, int bytesNeeded) throws IOException { 37 | int bytesToRead = Math.min(chunk.length, Math.min(bytesNeeded, buffer.remaining())); 38 | if (bytesToRead == 0) { 39 | return -1; 40 | } 41 | 42 | buffer.get(chunk, 0, bytesToRead); 43 | return bytesToRead; 44 | } 45 | 46 | @Override 47 | public boolean isAvailable() { 48 | return super.isAvailable() || buffer.hasRemaining(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/io/EmptyByteChunkProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.io; 17 | 18 | public class EmptyByteChunkProvider extends ByteChunkProvider { 19 | public EmptyByteChunkProvider(long fileOffset) { 20 | this.offset = fileOffset; 21 | } 22 | 23 | @Override 24 | public void prepareWrite(int maxBytesToPrepare) { 25 | // Nothing to prepare, is empty 26 | } 27 | 28 | @Override 29 | public boolean isAvailable() { 30 | return false; 31 | } 32 | 33 | @Override 34 | protected int getChunk(byte[] chunk) { 35 | return 0; 36 | } 37 | 38 | @Override 39 | public int bytesLeft() { 40 | return 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/paths/PathResolveException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.paths; 17 | 18 | import com.hierynomus.mserref.NtStatus; 19 | 20 | @SuppressWarnings("serial") 21 | public class PathResolveException extends Exception { 22 | private final long status; 23 | 24 | public PathResolveException(long status) { 25 | this.status = status; 26 | } 27 | 28 | public PathResolveException(long status, String message) { 29 | super(message); 30 | this.status = status; 31 | } 32 | 33 | public PathResolveException(Throwable cause) { 34 | super(cause); 35 | this.status = NtStatus.STATUS_OTHER.getValue(); 36 | } 37 | 38 | public long getStatusCode() { 39 | return status; 40 | } 41 | 42 | public NtStatus getStatus() { 43 | return NtStatus.valueOf(status); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/server/ServerList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.server; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | import java.util.concurrent.locks.ReentrantLock; 21 | 22 | public class ServerList { 23 | private ReentrantLock lock = new ReentrantLock(); 24 | private Map lookup = new HashMap<>(); 25 | 26 | public Server lookup(String name) { 27 | lock.lock(); 28 | try { 29 | return lookup.get(name); 30 | } finally { 31 | lock.unlock(); 32 | } 33 | } 34 | 35 | public void registerServer(Server server) { 36 | lock.lock(); 37 | try { 38 | lookup.put(server.getServerName(), server); 39 | } finally { 40 | lock.unlock(); 41 | } 42 | } 43 | 44 | public void unregister(String name) { 45 | lock.lock(); 46 | try { 47 | lookup.remove(name); 48 | } finally { 49 | lock.unlock(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/session/SMB2GuestSigningRequiredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.session; 17 | 18 | import com.hierynomus.smbj.common.SMBRuntimeException; 19 | 20 | @SuppressWarnings("serial") 21 | public class SMB2GuestSigningRequiredException extends SMBRuntimeException { 22 | public SMB2GuestSigningRequiredException() { 23 | super("Cannot require message signing when authenticating with a guest account"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/share/StatusHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.share; 17 | 18 | import com.hierynomus.mserref.NtStatus; 19 | 20 | public interface StatusHandler { 21 | StatusHandler SUCCESS = new StatusHandler() { 22 | @Override 23 | public boolean isSuccess(long statusCode) { 24 | return statusCode == NtStatus.STATUS_SUCCESS.getValue(); 25 | } 26 | }; 27 | 28 | boolean isSuccess(long statusCode); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/transport/TransportLayerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.transport; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | import com.hierynomus.protocol.PacketData; 20 | import com.hierynomus.protocol.transport.PacketHandlers; 21 | import com.hierynomus.protocol.transport.TransportLayer; 22 | import com.hierynomus.smbj.SmbConfig; 23 | 24 | public interface TransportLayerFactory, P extends Packet> { 25 | 26 | TransportLayer

createTransportLayer(PacketHandlers handlers, SmbConfig config); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/transport/tcp/direct/DirectTcpTransportFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.transport.tcp.direct; 17 | 18 | import com.hierynomus.protocol.Packet; 19 | import com.hierynomus.protocol.PacketData; 20 | import com.hierynomus.protocol.transport.PacketHandlers; 21 | import com.hierynomus.protocol.transport.TransportLayer; 22 | import com.hierynomus.smbj.SmbConfig; 23 | import com.hierynomus.smbj.transport.TransportLayerFactory; 24 | 25 | public class DirectTcpTransportFactory, P extends Packet> implements TransportLayerFactory { 26 | @Override 27 | public TransportLayer

createTransportLayer(PacketHandlers handlers, SmbConfig config) { 28 | return new DirectTcpTransport<>(config.getSocketFactory(), config.getSoTimeout(), handlers); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/smbj/utils/DigestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.utils; 17 | 18 | import com.hierynomus.security.MessageDigest; 19 | 20 | public class DigestUtil { 21 | 22 | public static byte[] digest(MessageDigest digest, byte[] previous, byte[] extra) { 23 | digest.reset(); 24 | digest.update(previous); 25 | digest.update(extra); 26 | return digest.digest(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/spnego/ObjectIdentifiers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.spnego; 17 | 18 | 19 | import com.hierynomus.asn1.types.primitive.ASN1ObjectIdentifier; 20 | 21 | public class ObjectIdentifiers { 22 | public static final ASN1ObjectIdentifier SPNEGO = new ASN1ObjectIdentifier("1.3.6.1.5.5.2"); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/spnego/RawToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.spnego; 17 | 18 | import com.hierynomus.asn1.types.constructed.ASN1TaggedObject; 19 | import com.hierynomus.protocol.commons.buffer.Buffer; 20 | 21 | public class RawToken extends SpnegoToken { 22 | private byte[] rawToken; 23 | 24 | public RawToken(byte[] rawToken) { 25 | super(0, null); 26 | this.rawToken = rawToken; 27 | } 28 | 29 | @Override 30 | protected void parseTagged(ASN1TaggedObject asn1TaggedObject) throws SpnegoException { 31 | throw new UnsupportedOperationException("RawToken does not support parsing of tagged objects"); 32 | } 33 | 34 | @Override 35 | public void write(Buffer buffer) throws SpnegoException { 36 | if (rawToken != null) { 37 | buffer.putRawBytes(rawToken); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hierynomus/spnego/SpnegoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.spnego; 17 | 18 | import java.io.IOException; 19 | 20 | @SuppressWarnings("serial") 21 | public class SpnegoException extends Exception { 22 | public SpnegoException(String message) { 23 | super(message); 24 | } 25 | 26 | public SpnegoException(String message, IOException e) { 27 | super(message, e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/msdfsc/DirectFuture.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdfsc 17 | 18 | import java.util.concurrent.ExecutionException 19 | import java.util.concurrent.Future 20 | import java.util.concurrent.TimeUnit 21 | import java.util.concurrent.TimeoutException 22 | 23 | class DirectFuture implements Future { 24 | 25 | private V contents 26 | 27 | DirectFuture(V contents) { 28 | this.contents = contents 29 | } 30 | 31 | @Override 32 | boolean cancel(boolean mayInterruptIfRunning) { 33 | return false 34 | } 35 | 36 | @Override 37 | boolean isCancelled() { 38 | return false 39 | } 40 | 41 | @Override 42 | boolean isDone() { 43 | return true 44 | } 45 | 46 | @Override 47 | V get() throws InterruptedException, ExecutionException { 48 | return contents 49 | } 50 | 51 | @Override 52 | V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { 53 | return contents 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/msdfsc/StubResponder.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdfsc 17 | 18 | import com.hierynomus.mssmb2.SMB2Packet 19 | 20 | class StubResponder { 21 | 22 | Map> responses = [:] 23 | 24 | def register(Class c, SMB2Packet response) { 25 | def queue = responses.get(c) 26 | if (!queue) { 27 | queue = new ArrayDeque() 28 | responses.put(c, queue) 29 | } 30 | queue.add(response) 31 | } 32 | 33 | SMB2Packet respond(Object o) { 34 | def clazz = o.getClass() 35 | if (responses.containsKey(clazz)) { 36 | return responses.get(clazz).poll() 37 | } 38 | throw new IllegalArgumentException("$clazz has no registered response") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/mssmb2/SMB2ErrorSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2 17 | 18 | import com.hierynomus.smb.SMBBuffer 19 | import spock.lang.Specification 20 | 21 | class SMB2ErrorSpec extends Specification { 22 | 23 | def "ErrorData - Empty"() { 24 | given: 25 | def header = new SMB2PacketHeader() 26 | def buffer = new SMBBuffer() 27 | buffer.putReserved(2) 28 | buffer.putReserved(1) 29 | buffer.putReserved(1) 30 | buffer.putUInt32(0L) 31 | buffer.putReserved(1) 32 | 33 | when: 34 | def error = new SMB2Error() 35 | error.read(header, buffer) 36 | 37 | then: 38 | error.getErrorData().size() == 0 39 | } 40 | 41 | def "ErrorData - Empty - W10 1709"() { 42 | given: 43 | def header = new SMB2PacketHeader() 44 | def buffer = new SMBBuffer() 45 | buffer.putReserved(2) 46 | buffer.putReserved(1) 47 | buffer.putReserved(1) 48 | buffer.putUInt32(0L) 49 | // No ErrorData reserved byte provided 50 | 51 | when: 52 | def error = new SMB2Error() 53 | error.read(header, buffer) 54 | 55 | then: 56 | error.getErrorData().size() == 0 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/mssmb2/SMB2MessageFlagSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2 17 | 18 | import com.hierynomus.protocol.commons.EnumWithValue 19 | import spock.lang.Specification 20 | 21 | class SMB2MessageFlagSpec extends Specification { 22 | 23 | def "should correctly detect that flag is set"() { 24 | given: 25 | long b = 0x10000001 26 | 27 | when: 28 | def flagses = EnumWithValue.EnumUtils.toEnumSet(b, SMB2MessageFlag.class) 29 | 30 | then: 31 | flagses.size() == 2 32 | flagses.contains(SMB2MessageFlag.SMB2_FLAGS_DFS_OPERATIONS) 33 | flagses.contains(SMB2MessageFlag.SMB2_FLAGS_SERVER_TO_REDIR) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/mssmb2/SMB2PacketHeaderSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2 17 | 18 | import com.hierynomus.smb.SMBBuffer 19 | import spock.lang.Specification 20 | import spock.lang.Unroll 21 | 22 | class SMB2PacketHeaderSpec extends Specification { 23 | 24 | @Unroll 25 | def "should write credit request for dialect #dialect"() { 26 | given: 27 | def header = new SMB2PacketHeader() 28 | header.setCreditRequest(66) 29 | header.setCreditCharge(0) 30 | header.setDialect(dialect) 31 | header.setMessageType(SMB2MessageCommandCode.SMB2_NEGOTIATE) 32 | def buffer = new SMBBuffer() 33 | 34 | when: 35 | header.writeTo(buffer) 36 | 37 | then: 38 | buffer.rpos(14) 39 | buffer.readUInt16() == 66 40 | 41 | where: 42 | dialect << [SMB2Dialect.SMB_2_1, SMB2Dialect.SMB_2_0_2, SMB2Dialect.SMB_2XX] 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/mssmb2/messages/AbstractPacketReadSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages 17 | 18 | import com.hierynomus.mssmb2.SMB2MessageConverter 19 | import com.hierynomus.mssmb2.SMB2PacketData 20 | import spock.lang.Shared 21 | import spock.lang.Specification 22 | 23 | class AbstractPacketReadSpec extends Specification { 24 | @Shared 25 | def converter = new SMB2MessageConverter() 26 | 27 | def convert(byte[] bytes) { 28 | def packetData = new SMB2PacketData(bytes) 29 | return converter.readPacket(null, packetData) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/mssmb2/messages/SMB2WriteResponseSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mssmb2.messages 17 | 18 | import com.hierynomus.protocol.commons.ByteArrayUtils 19 | 20 | class SMB2WriteResponseSpec extends AbstractPacketReadSpec { 21 | 22 | def "should parse write response"() { 23 | given: 24 | String hexString1 = "fe534d4240000000000000000900010001000000000000004d00000000000000000000000100000061000000007400000000000000000000000000000000000011000000002000000000000000000000" 25 | byte[] bytes1 = ByteArrayUtils.parseHex(hexString1) 26 | 27 | when: 28 | def response = convert(bytes1) 29 | 30 | then: 31 | response.class == SMB2WriteResponse.class 32 | with(response as SMB2WriteResponse) { r -> 33 | r.bytesWritten == 8192 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/security/jce/JceMessageDigestSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.security.jce 17 | 18 | import spock.lang.Specification 19 | 20 | class JceMessageDigestSpec extends Specification { 21 | 22 | def "should be able to load MD4 from the regular JRE/JDK"() { 23 | given: 24 | def provider = new JceSecurityProvider() 25 | 26 | when: 27 | provider.getDigest("MD4") 28 | 29 | then: 30 | noExceptionThrown() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/smbj/io/InputStreamByteChunkProviderSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.io 17 | 18 | import spock.lang.Specification 19 | 20 | class InputStreamByteChunkProviderSpec extends Specification { 21 | 22 | def "should close underlying input stream when closing provider"() { 23 | given: 24 | def is = Mock(InputStream) 25 | def provider = new InputStreamByteChunkProvider(is) 26 | 27 | when: 28 | provider.close() 29 | 30 | then: 31 | 1 * is.close() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/smbj/transport/tcp/async/AsyncDirectTcpTransportSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.transport.tcp.async 17 | 18 | import com.hierynomus.smbj.SMBClient 19 | import com.hierynomus.smbj.SmbConfig 20 | import com.hierynomus.smbj.server.StubSmbServer 21 | import spock.lang.Shared 22 | import spock.lang.Specification 23 | 24 | class AsyncDirectTcpTransportSpec extends Specification { 25 | 26 | @Shared 27 | def config = SmbConfig.builder().withTransportLayerFactory(new AsyncDirectTcpTransportFactory()).build() 28 | 29 | StubSmbServer server 30 | 31 | def setup() { 32 | server = new StubSmbServer() 33 | } 34 | 35 | def cleanup() { 36 | server.shutdown() 37 | } 38 | 39 | def "client should connect to AsyncDirectTcpTransport"() { 40 | given: 41 | server.registerResponse("com/hierynomus/smbj/transport/tcp/async/nego-response.pcap") 42 | server.start() 43 | def client = new SMBClient(config) 44 | 45 | when: 46 | def connection = client.connect("localhost", server.port) 47 | 48 | then: 49 | noExceptionThrown() 50 | connection.isConnected() 51 | connection.close() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/groovy/com/hierynomus/test/PredictableRandom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.test; 17 | 18 | import java.util.Random; 19 | 20 | public class PredictableRandom extends Random { 21 | private byte[] randomBytes; 22 | private int idx; 23 | 24 | public void init(byte[] bytes) { 25 | this.randomBytes = bytes; 26 | this.idx = 0; 27 | } 28 | 29 | @Override 30 | public void nextBytes(byte[] bytes) { 31 | for (int i = 0; i < bytes.length; i++) { 32 | bytes[i] = randomBytes[(idx + i) % randomBytes.length]; 33 | } 34 | idx = (idx + bytes.length) % randomBytes.length; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/hierynomus/msdtyp/MsDataTypesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.msdtyp; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import java.util.UUID; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import com.hierynomus.smb.SMBBuffer; 25 | 26 | public class MsDataTypesTest { 27 | @Test 28 | public void shouldReadWriteUUIDCorrect() throws Exception { 29 | SMBBuffer buffer = new SMBBuffer(); 30 | UUID uuid = UUID.fromString("fbbd1895-af40-48a4-a183-8dabeb1e901a"); 31 | 32 | MsDataTypes.putGuid(uuid, buffer); 33 | assertEquals("95 18 bd fb 40 af a4 48 a1 83 8d ab eb 1e 90 1a", buffer.printHex()); 34 | assertEquals(uuid, MsDataTypes.readGuid(buffer)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/hierynomus/mserref/NtStatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.mserref; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertTrue; 19 | 20 | import org.junit.jupiter.params.ParameterizedTest; 21 | import org.junit.jupiter.params.provider.EnumSource; 22 | 23 | public class NtStatusTest { 24 | @ParameterizedTest(name = "{0} should have STATUS_SEVERITY_SUCCESS status") 25 | @EnumSource(value = NtStatus.class, names = {"STATUS_SUCCESS", "STATUS_PENDING"}) 26 | public void shouldHaveSuccessStatus(NtStatus s) { 27 | assertTrue(s.isSuccess()); 28 | } 29 | 30 | @ParameterizedTest(name = "{0} should have STATUS_SEVERITY_ERROR status") 31 | @EnumSource(value = NtStatus.class, names = {"STATUS_ACCESS_DENIED", "STATUS_END_OF_FILE"}) 32 | public void shouldHaveErrorStatus(NtStatus s) { 33 | assertTrue(s.isError()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/hierynomus/smbj/SmbConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertThrows; 19 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.hierynomus.mssmb2.SMB2Dialect; 24 | 25 | public class SmbConfigTest { 26 | @Test 27 | public void testCreateDefaultConfig() { 28 | assertDoesNotThrow(() -> SmbConfig.createDefaultConfig()); 29 | } 30 | 31 | @Test 32 | public void shouldNotBuildConfigWithRequiredAndDisabledSigning() { 33 | assertThrows(IllegalStateException.class, 34 | () -> SmbConfig.builder().withDialects(SMB2Dialect.SMB_2_0_2).withSigningRequired(true).withSigningEnabled(false).build()); 35 | } 36 | 37 | @Test 38 | public void shouldNotBuildConfigWithDisabledSigningAndSmb3xDialect() { 39 | assertThrows(IllegalStateException.class, 40 | () -> SmbConfig.builder().withDialects(SMB2Dialect.SMB_3_0).withSigningEnabled(false).build()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/hierynomus/smbj/testing/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2016 - SMBJ Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hierynomus.smbj.testing; 17 | 18 | import com.hierynomus.smbj.SmbConfig; 19 | import com.hierynomus.smbj.testing.PacketProcessor.DefaultPacketProcessor; 20 | 21 | public class Utils { 22 | public static SmbConfig config(PacketProcessor processor) { 23 | return configBuilder(processor).build(); 24 | } 25 | 26 | public static SmbConfig.Builder configBuilder(PacketProcessor processor) { 27 | return SmbConfig.builder() 28 | .withTransportLayerFactory(new StubTransportLayerFactory<>(new DefaultPacketProcessor().wrap(processor))) 29 | .withAuthenticators(new StubAuthenticator.Factory()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/resources/com/hierynomus/smbj/transport/tcp/async/nego-response.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/src/test/resources/com/hierynomus/smbj/transport/tcp/async/nego-response.pcap -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%.-20thread] %-5level %logger{36} - %msg%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/test/resources/spnego/negTokenInit_ntlm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/src/test/resources/spnego/negTokenInit_ntlm -------------------------------------------------------------------------------- /src/test/resources/spnego/negTokenInit_resp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/src/test/resources/spnego/negTokenInit_resp -------------------------------------------------------------------------------- /src/test/resources/spnego/negTokenTarg_ntlmchallenge: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hierynomus/smbj/f62e50fcbdbe02dddc6725d931c4b8f2777bf665/src/test/resources/spnego/negTokenTarg_ntlmchallenge --------------------------------------------------------------------------------