001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.security.ntlm.msrpc;
016    
017    import jcifs.dcerpc.ndr.NdrBuffer;
018    import jcifs.dcerpc.ndr.NdrObject;
019    
020    /**
021     * @author Marcellus Tavares
022     */
023    public class NetlogonNetworkInfo extends NdrObject {
024    
025            public NetlogonNetworkInfo(
026                    NetlogonIdentityInfo netlogonIdentityInfo, byte[] lmChallenge,
027                    byte[] ntChallengeResponse, byte[] lmChallengeResponse) {
028    
029                    _netlogonIdentityInfo = netlogonIdentityInfo;
030                    _lmChallenge = lmChallenge;
031                    _ntChallengeResponse = ntChallengeResponse;
032                    _lmChallengeResponse = lmChallengeResponse;
033            }
034    
035            @Override
036            public void decode(NdrBuffer ndrBuffer) {
037            }
038    
039            @Override
040            public void encode(NdrBuffer ndrBuffer) {
041                    ndrBuffer.align(4);
042    
043                    _netlogonIdentityInfo.encode(ndrBuffer);
044    
045                    int lmChallengeIndex = ndrBuffer.index;
046    
047                    ndrBuffer.advance(8);
048    
049                    ndrBuffer.enc_ndr_short((short)_ntChallengeResponse.length);
050                    ndrBuffer.enc_ndr_short((short)_ntChallengeResponse.length);
051                    ndrBuffer.enc_ndr_referent(_ntChallengeResponse, 1);
052    
053                    ndrBuffer.enc_ndr_short((short)_lmChallengeResponse.length);
054                    ndrBuffer.enc_ndr_short((short)_lmChallengeResponse.length);
055                    ndrBuffer.enc_ndr_referent(_lmChallengeResponse, 1);
056    
057                    _netlogonIdentityInfo.encodeLogonDomainName(ndrBuffer);
058                    _netlogonIdentityInfo.encodeUserName(ndrBuffer);
059                    _netlogonIdentityInfo.encodeWorkStationName(ndrBuffer);
060    
061                    ndrBuffer = ndrBuffer.derive(lmChallengeIndex);
062    
063                    for (int i = 0; i < 8; i++) {
064                            ndrBuffer.enc_ndr_small(_lmChallenge[i]);
065                    }
066    
067                    encodeChallengeResponse(ndrBuffer, _ntChallengeResponse);
068                    encodeChallengeResponse(ndrBuffer, _lmChallengeResponse);
069            }
070    
071            protected void encodeChallengeResponse(
072                    NdrBuffer ndrBuffer, byte[] challenge) {
073    
074                    ndrBuffer = ndrBuffer.deferred;
075    
076                    ndrBuffer.enc_ndr_long(challenge.length);
077                    ndrBuffer.enc_ndr_long(0);
078                    ndrBuffer.enc_ndr_long(challenge.length);
079    
080                    int index = ndrBuffer.index;
081    
082                    ndrBuffer.advance(challenge.length);
083    
084                    ndrBuffer = ndrBuffer.derive(index);
085    
086                    for (int i = 0; i < challenge.length; i++) {
087                            ndrBuffer.enc_ndr_small(challenge[i]);
088                    }
089            }
090    
091            private byte[] _lmChallenge;
092            private byte[] _lmChallengeResponse;
093            private NetlogonIdentityInfo _netlogonIdentityInfo;
094            private byte[] _ntChallengeResponse;
095    
096    }