WEB开发网
开发学院软件开发Java 用 Kerberos 为 J2ME 应用程序上锁,第 3 部分: 建... 阅读

用 Kerberos 为 J2ME 应用程序上锁,第 3 部分: 建立与电子银行的安全通信(下)

 2010-03-30 00:00:00 来源:WEB开发网   
核心提示: 清单 19 的 getAuthenticationHeader() 方法逐一生成这五个字段,然后以正确的顺序将各个字段串接起来以形成一个完整的认证头,用 Kerberos 为 J2ME 应用程序上锁,第 3 部分: 建立与电子银行的安全通信(下)(6), 清单 19. getAuthentica

清单 19 的 getAuthenticationHeader() 方法逐一生成这五个字段,然后以正确的顺序将各个字段串接起来以形成一个完整的认证头。

清单 19. getAuthenticationHeader() 方法

  public byte[] getAuthenticationHeader( byte[] ticketContent, 
                 String clientRealm, 
                 String clientName, 
                 byte[] checksumBytes, 
                 byte[] encryptionKey, 
                 int sequenceNumber 
                ) 
  { 
   byte[] authenticator = null; 
   byte[] vno = getTagAndLengthBytes ( 
           ASN1DataTypes.CONTEXT_SPECIFIC, 
             0, getIntegerBytes(5) 
          ); 
   byte[] ap_req_msg_type = getTagAndLengthBytes( 
                 ASN1DataTypes.CONTEXT_SPECIFIC, 
                 1, getIntegerBytes(14) 
                ); 
   byte[] ap_options = getTagAndLengthBytes( 
              ASN1DataTypes.CONTEXT_SPECIFIC, 
              2, getBitStringBytes(new byte[5]) 
            ); 
   byte[] ticket = getTagAndLengthBytes( 
            ASN1DataTypes.CONTEXT_SPECIFIC, 
            3, ticketContent 
           ); 
   byte[] realmName = getTagAndLengthBytes(ASN1DataTypes.CONTEXT_SPECIFIC, 
             1, getGeneralStringBytes(clientRealm) 
            ); 
   byte[] generalStringSequence = getSequenceBytes( 
                    getGeneralStringBytes (clientName) 
                   ); 
   byte[] name_string = getTagAndLengthBytes(ASN1DataTypes.CONTEXT_SPECIFIC, 
               1, generalStringSequence 
              ); 
   byte[] name_type = getTagAndLengthBytes(ASN1DataTypes.CONTEXT_SPECIFIC, 
            0, getIntegerBytes(ASN1DataTypes.NT_PRINCIPAL) 
          ); 
   byte[] clientNameSequence = getSequenceBytes( 
                   concatenateBytes (name_type, name_string) 
                 ); 
   byte[] cName = getTagAndLengthBytes(ASN1DataTypes.CONTEXT_SPECIFIC, 
            2, clientNameSequence); 
   byte[] cusec = getTagAndLengthBytes(ASN1DataTypes.CONTEXT_SPECIFIC, 
            4, getIntegerBytes(0) 
           ); 
   byte[] ctime = getTagAndLengthBytes(ASN1DataTypes.CONTEXT_SPECIFIC, 
            5, getGeneralizedTimeBytes ( 
             getUTCTimeString(System.currentTimeMillis()).getBytes() 
            ) 
        ); 
     
   if (sequenceNumber !=0 ) { 
     byte[] etype = getTagAndLengthBytes ( 
             ASN1DataTypes.CONTEXT_SPECIFIC, 
           0, getIntegerBytes(3) 
           ); 
     byte[] eKey = getTagAndLengthBytes ( 
            ASN1DataTypes.CONTEXT_SPECIFIC, 
              1, getOctetStringBytes(encryptionKey) 
           ); 
     byte[] subKey_sequence = getSequenceBytes (concatenateBytes(etype, eKey)); 
     byte[] subKey = getTagAndLengthBytes( 
              ASN1DataTypes.CONTEXT_SPECIFIC, 
              6, subKey_sequence 
            ); 
     byte[] sequenceNumberBytes = { 
      (byte)0xff, 
      (byte)0xff, 
      (byte)0xff, 
      (byte)0xff 
     }; 
   
     sequenceNumberBytes[3] = (byte)sequenceNumber; 
     byte[] seqNumber = getTagAndLengthBytes( 
                ASN1DataTypes.CONTEXT_SPECIFIC, 
                7, getIntegerBytes(sequenceNumberBytes) 
              ); 
     authenticator = getTagAndLengthBytes(ASN1DataTypes.APPLICATION_TYPE, 
             2, getSequenceBytes( 
               concatenateBytes(vno, 
                concatenateBytes(realmName, 
                  concatenateBytes(cName, 
                   concatenateBytes(checksumBytes, 
                     concatenateBytes(cusec, 
                      concatenateBytes(ctime, 
                        concatenateBytes(subKey,seqNumber) 
                      ) 
                     ) 
                   ) 
                  ) 
                ) 
               ) 
             ) 
            ); 
     } else { 
     authenticator = getTagAndLengthBytes(ASN1DataTypes.APPLICATION_TYPE, 
         2, getSequenceBytes( 
            concatenateBytes(vno, 
           concatenateBytes(realmName, 
               concatenateBytes(cName, 
                 concatenateBytes(checksumBytes, 
                  concatenateBytes(cusec,ctime) 
                 ) 
               ) 
              ) 
            ) 
           ) 
         ); 
     }//if (sequenceNumber !=null) 
     byte[] enc_authenticator = getTagAndLengthBytes( 
                   ASN1DataTypes.CONTEXT_SPECIFIC, 
                   4, authorDigestAndEncrypt(encryptionKey, authenticator) 
                  ); 
     byte[] ap_req = getTagAndLengthBytes ( 
              ASN1DataTypes.APPLICATION_TYPE, 
               14, getSequenceBytes( 
                 concatenateBytes (vno, 
                  concatenateBytes(ap_req_msg_type, 
                    concatenateBytes(ap_options, 
                     concatenateBytes(ticket, enc_authenticator) 
                    ) 
                   ) 
                 ) 
                ) 
              ); 
    return ap_req; 
  }//getAuthenticationHeader 

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Kerberos JME 应用程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接