Package org.apache.directory.shared.kerberos.components

Examples of org.apache.directory.shared.kerberos.components.EncKrbPrivPart


        ChangePasswdData passwordData = null;
       
        try
        {
            byte[] decryptedData = cipherTextHandler.decrypt( subSessionKey, encReqPrivPart, KeyUsage.KRB_PRIV_ENC_PART_CHOSEN_KEY );
            EncKrbPrivPart privatePart = KerberosDecoder.decodeEncKrbPrivPart( decryptedData );

            if( authenticator.getSeqNumber() != privatePart.getSeqNumber() )
            {
                throw new ChangePasswordException( ChangePasswdErrorType.KRB5_KPASSWD_MALFORMED );   
            }
           
            if ( request.getVersionNumber() == AbstractPasswordMessage.OLD_PVNO )
            {
                passwordData = new ChangePasswdData();
                passwordData.setNewPasswd( privatePart.getUserData() );
            }
            else
            {
                Asn1Decoder passwordDecoder = new Asn1Decoder();
                ByteBuffer stream = ByteBuffer.wrap( privatePart.getUserData() );
                ChangePasswdDataContainer container = new ChangePasswdDataContainer( stream );
                passwordDecoder.decode( stream, container );
                passwordData = container.getChngPwdData();
            }
        }
View Full Code Here


        // begin building reply

        // create priv message
        // user-data component is short result code
        EncKrbPrivPart privPart = new EncKrbPrivPart();
        // first two bytes are the result code, rest is the string 'Password Changed' followed by a null char
        byte[] resultCode =
            { ( byte ) 0x00, ( byte ) 0x00, (byte)0x50, (byte)0x61, (byte)0x73, (byte)0x73, (byte)0x77, (byte)0x6F, (byte)0x72, (byte)0x64, (byte)0x20, (byte)0x63, (byte)0x68, (byte)0x61, (byte)0x6E, (byte)0x67, (byte)0x65, (byte)0x64, (byte)0x00 };
        privPart.setUserData( resultCode );

        privPart.setSenderAddress( new HostAddress( InetAddress.getLocalHost() ) );

        // get the subsession key from the Authenticator
        EncryptionKey subSessionKey = authenticator.getSubKey();

        EncryptedData encPrivPart;
View Full Code Here

        catch ( DecoderException e )
        {
            fail();
        }

        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();

        String time = "20101119080043Z";
        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );

        assertTrue( Arrays.equals( new byte[]
            { 0, 1 }, encKrbPrivPart.getUserData() ) );
        assertEquals( time, encKrbPrivPart.getTimestamp().getDate() );
        assertEquals( 1, encKrbPrivPart.getUsec() );
        assertEquals( 1, encKrbPrivPart.getSeqNumber() );
        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );

        int computedLen = encKrbPrivPart.computeLength();

        assertEquals( streamLen, computedLen );

        try
        {
            ByteBuffer bb = ByteBuffer.allocate( computedLen );

            encKrbPrivPart.encode( bb );

            String encoded = Strings.dumpBytes( bb.array() );
            assertEquals( decoded, encoded );
        }
        catch ( EncoderException e )
View Full Code Here

        {
            throw new KerberosException( ErrorType.KRB_AP_ERR_BAD_INTEGRITY, de );
        }

        // get the decoded EncKrbPrivPart
        EncKrbPrivPart encKrbPrivPart = ( ( EncKrbPrivPartContainer ) encKrbPrivPartContainer ).getEncKrbPrivPart();

        return encKrbPrivPart;
    }
View Full Code Here

        ApRep apRep = chngPwdReply.getApplicationReply();
       
        KrbPriv krbPriv = chngPwdReply.getPrivateMessage();
        byte[] decryptedKrbPrivPart = cipherTextHandler.decrypt( subSessionKey, krbPriv.getEncPart(), KeyUsage.KRB_PRIV_ENC_PART_CHOSEN_KEY );
        EncKrbPrivPart krbPrivPart = KerberosDecoder.decodeEncKrbPrivPart( decryptedKrbPrivPart );
        System.out.println( krbPrivPart );
    }
View Full Code Here

            apReq.setAuthenticator( authData );
           
           
            KrbPriv privateMessage = new KrbPriv();
           
            EncKrbPrivPart part = new EncKrbPrivPart();
            part.setSenderAddress( new HostAddress( InetAddress.getLocalHost() ) );
            part.setSeqNumber( authenticator.getSeqNumber() );
            part.setTimestamp( authenticator.getCtime() );

            short changePwdPVNO = ChangePasswordRequest.PVNO;
           
            if( config.isUseLegacyChngPwdProtocol() )
            {
                part.setUserData( Strings.getBytesUtf8( newPassword ) );
                changePwdPVNO = ChangePasswordRequest.OLD_PVNO;
            }
            else
            {
                ChangePasswdData chngPwdData = new ChangePasswdData();
                chngPwdData.setNewPasswd( Strings.getBytesUtf8( newPassword ) );
                //chngPwdData.setTargName( new PrincipalName( clientPrincipal, PrincipalNameType.KRB_NT_PRINCIPAL ) );
                //chngPwdData.setTargRealm( clientTgtReq.getRealm() );
                byte[] data = getEncoded( chngPwdData );
                part.setUserData( data );
            }
           
            EncryptedData encKrbPrivPartData = cipherTextHandler.encrypt( subKey, getEncoded( part ), KeyUsage.KRB_PRIV_ENC_PART_CHOSEN_KEY );
            privateMessage.setEncPart( encKrbPrivPartData );
           
            ChangePasswordRequest req = new ChangePasswordRequest( changePwdPVNO, apReq, privateMessage );
           
            channel = new KerberosChannel();
            channel.openConnection( config.getHostName(), config.getPasswdPort(), config.getTimeout(), config.isUseUdp() );
           
            AbstractPasswordMessage reply = sendAndReceiveChngPwdMsg( req, channel );
           
            if ( reply instanceof ChangePasswordError )
            {
                ChangePasswordError err = ( ChangePasswordError ) reply;
               
                ChangePasswordResult result = new ChangePasswordResult( err.getKrbError().getEData() );

                return result;
            }
           
            ChangePasswordReply chngPwdReply = ( ChangePasswordReply ) reply;

            KrbPriv replyPriv = chngPwdReply.getPrivateMessage();
            // the same subKey present in ApReq is used for encrypting the KrbPriv present in reply
            byte[] data = cipherTextHandler.decrypt( subKey, replyPriv.getEncPart(), KeyUsage.KRB_PRIV_ENC_PART_CHOSEN_KEY );
            part = KerberosDecoder.decodeEncKrbPrivPart( data );
           
            ChangePasswordResult result = new ChangePasswordResult( part.getUserData() );
           
            return result;
        }
        catch( ChangePasswordException e )
        {
View Full Code Here

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
        }

        EncKrbPrivPart encKrbPrivPart = new EncKrbPrivPart();
        encKrbPrivPartContainer.setEncKrbPrivPart( encKrbPrivPart );

        if ( IS_DEBUG )
        {
            LOG.debug( "EncKrbPrivPart created" );
View Full Code Here

        catch ( DecoderException e )
        {
            fail();
        }

        EncKrbPrivPart enKrbPrivPart = container.getEncKrbPrivPart();

        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );

        assertTrue( Arrays.equals( new byte[]
            { 0, 1 }, enKrbPrivPart.getUserData() ) );
        assertNull( enKrbPrivPart.getTimestamp() );
        assertEquals( 1, enKrbPrivPart.getUsec() );
        assertEquals( 1, enKrbPrivPart.getSeqNumber() );
        assertEquals( ad, enKrbPrivPart.getSenderAddress() );
        assertEquals( ad, enKrbPrivPart.getRecipientAddress() );

        int computedLen = enKrbPrivPart.computeLength();

        assertEquals( streamLen, computedLen );

        try
        {
            ByteBuffer bb = ByteBuffer.allocate( computedLen );

            enKrbPrivPart.encode( bb );

            String encoded = Strings.dumpBytes( bb.array() );
            assertEquals( decoded, encoded );
        }
        catch ( EncoderException e )
View Full Code Here

        catch ( DecoderException e )
        {
            fail();
        }

        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();

        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );

        assertTrue( Arrays.equals( new byte[]
            { 0, 1 }, encKrbPrivPart.getUserData() ) );
        assertNull( encKrbPrivPart.getTimestamp() );
        assertEquals( 0, encKrbPrivPart.getUsec() );
        assertEquals( 1, encKrbPrivPart.getSeqNumber() );
        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );

        int computedLen = encKrbPrivPart.computeLength();

        assertEquals( streamLen, computedLen );

        try
        {
            ByteBuffer bb = ByteBuffer.allocate( computedLen );

            encKrbPrivPart.encode( bb );

            String encoded = Strings.dumpBytes( bb.array() );
            assertEquals( decoded, encoded );
        }
        catch ( EncoderException e )
View Full Code Here

        {
            e.printStackTrace();
            fail();
        }

        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();

        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );

        assertTrue( Arrays.equals( new byte[]
            { 0, 1 }, encKrbPrivPart.getUserData() ) );
        assertNull( encKrbPrivPart.getTimestamp() );
        assertEquals( 0, encKrbPrivPart.getUsec() );
        assertEquals( 0, encKrbPrivPart.getSeqNumber() );
        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );

        int computedLen = encKrbPrivPart.computeLength();

        assertEquals( streamLen, computedLen );

        try
        {
            ByteBuffer bb = ByteBuffer.allocate( computedLen );

            encKrbPrivPart.encode( bb );

            String encoded = Strings.dumpBytes( bb.array() );
            assertEquals( decoded, encoded );
        }
        catch ( EncoderException e )
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.kerberos.components.EncKrbPrivPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.