Ejemplo n.º 1
0
        public static void UpgradeBike()
        {
            var             basicBike = new CarbonBike();
            BikeAccessories upgraded  = new SportPackage(basicBike);

            upgraded = new SecurityPackage(upgraded);
            upgraded = new DiscountPackage(upgraded, 0.1);

            var             basicBike2 = new AluminiumBike();
            BikeAccessories upgraded2  = new SportPackage(basicBike2);

            upgraded2 = new SecurityPackage(upgraded2);

            System.Console.WriteLine($"Bike: '{upgraded.GetDetails()}' Cost: {upgraded.GetPrice()}");
            System.Console.WriteLine($"Bike: '{upgraded2.GetDetails()}' Cost: {upgraded2.GetPrice()}");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientSecurityCredential" /> class.
 /// </summary>
 /// <param name="package">The security package to use.</param>
 /// <exception cref="SspiException">The specified security package could not be found.</exception>
 public ClientSecurityCredential(SecurityPackage package)
     : this(SecurityPackageInfo.GetSecurityPackage(package))
 {
 }
        public Smb2NegotiateResponsePacket CreateNegotiateResponse(
            Smb2Endpoint endpoint,
            DialectRevision_Values dialectRevision,
            SecurityPackage securityPackage,
            ServerContextAttribute contextAttribute
            )
        {
            Smb2NegotiateResponsePacket packet = new Smb2NegotiateResponsePacket();

            SetHeader(packet, endpoint, 0);

            packet.PayLoad.SecurityMode |= NEGOTIATE_Response_SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED;

            if (context.requireMessageSigning)
            {
                packet.PayLoad.SecurityMode |= NEGOTIATE_Response_SecurityMode_Values.NEGOTIATE_SIGNING_REQUIRED;
            }

            packet.PayLoad.StructureSize = NEGOTIATE_Response_StructureSize_Values.V1;
            packet.PayLoad.DialectRevision = dialectRevision;
            packet.PayLoad.ServerGuid = context.serverGuid;

            if (context.isDfsCapable)
            {
                packet.PayLoad.Capabilities |= NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_DFS;
            }

            packet.PayLoad.MaxTransactSize = uint.MaxValue;
            packet.PayLoad.MaxWriteSize = uint.MaxValue;
            packet.PayLoad.MaxReadSize = uint.MaxValue;

            packet.PayLoad.SystemTime = Smb2Utility.DateTimeToFileTime(DateTime.Now);
            packet.PayLoad.ServerStartTime = Smb2Utility.DateTimeToFileTime(context.serverStartTime);

            SecurityPackageType package = SecurityPackageType.Negotiate;

            if (securityPackage == SecurityPackage.Kerberos)
            {
                package = SecurityPackageType.Kerberos;
            }
            else if (securityPackage == SecurityPackage.Nlmp)
            {
                package = SecurityPackageType.Ntlm;
            }

            AccountCredential credential = new AccountCredential(null, null, null);

            context.connectionList[endpoint.EndpointId].credential = credential;
            context.connectionList[endpoint.EndpointId].packageType = package;
            context.connectionList[endpoint.EndpointId].contextAttribute = (ServerSecurityContextAttribute)contextAttribute;

            if (package == SecurityPackageType.Negotiate)
            {
                context.connectionList[endpoint.EndpointId].gss = new SspiServerSecurityContext(
                    package,
                    credential,
                    null,
                    context.connectionList[endpoint.EndpointId].contextAttribute,
                    SecurityTargetDataRepresentation.SecurityNativeDrep);

                //Generate the first token
                context.connectionList[endpoint.EndpointId].gss.Accept(null);

                packet.PayLoad.Buffer = context.connectionList[endpoint.EndpointId].gss.Token;
                packet.PayLoad.SecurityBufferOffset = Smb2Consts.SecurityBufferOffsetInNegotiateResponse;
            }
            else
            {
                packet.PayLoad.Buffer = new byte[0];
            }
            packet.PayLoad.SecurityBufferLength = (ushort)packet.PayLoad.Buffer.Length;

            packet.Sign();

            return packet;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets information about the specified security package.
 /// </summary>
 /// <param name="packageName">The security package name.</param>
 /// <returns>A <see cref="SecurityPackageInfo" /> object representing the specified security package.</returns>
 /// <exception cref="SspiException">The specified security package could not be found.</exception>
 public static SecurityPackageInfo GetSecurityPackage(SecurityPackage packageName)
 {
     return(GetSecurityPackage(packageName.ToString()));
 }