Home | History | Annotate | Download | only in conscrypt
      1 /*
      2  * Copyright 2016 The Android Open Source Project
      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 package org.conscrypt;
     18 
     19 import static org.junit.Assert.assertArrayEquals;
     20 
     21 import org.junit.Test;
     22 
     23 public class TestSessionBuilderTest {
     24     @Test
     25     public void buildsValidBasicSession() {
     26         assertArrayEquals(new byte[] {0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x22, 0x00,
     27                                   0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x33},
     28                 new TestSessionBuilder()
     29                         .setType(0x11)
     30                         .setSessionData(new byte[] {0x22})
     31                         .addCertificate(new byte[] {0x33})
     32                         .build());
     33     }
     34 
     35     @Test
     36     public void buildsValidOcspSession() {
     37         assertArrayEquals(
     38                 new byte[] {
     39                         0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x22, 0x00, 0x00, 0x00,
     40                         0x01, 0x00, 0x00, 0x00, 0x01, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
     41                         0x00, 0x01, 0x44,
     42                 },
     43                 new TestSessionBuilder()
     44                         .setType(0x11)
     45                         .setSessionData(new byte[] {0x22})
     46                         .addCertificate(new byte[] {0x33})
     47                         .addOcspData(new byte[] {0x44})
     48                         .build());
     49     }
     50 
     51     @Test
     52     public void buildsValidOcspAndTlsSctSession() {
     53         assertArrayEquals(
     54                 new byte[] {
     55                         0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x22, 0x00, 0x00, 0x00,
     56                         0x01, 0x00, 0x00, 0x00, 0x01, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
     57                         0x00, 0x01, 0x44, 0x00, 0x00, 0x00, 0x01, 0x55,
     58                 },
     59                 new TestSessionBuilder()
     60                         .setType(0x11)
     61                         .setSessionData(new byte[] {0x22})
     62                         .addCertificate(new byte[] {0x33})
     63                         .addOcspData(new byte[] {0x44})
     64                         .setTlsSctData(new byte[] {0x55})
     65                         .build());
     66     }
     67 
     68     @Test
     69     public void buildsValidButEmptyOcspAndTlsSctSession() {
     70         assertArrayEquals(
     71                 new byte[] {
     72                         0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x22, 0x00, 0x00, 0x00,
     73                         0x01, 0x00, 0x00, 0x00, 0x01, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     74                         0x00, 0x00,
     75                 },
     76                 new TestSessionBuilder()
     77                         .setType(0x11)
     78                         .setSessionData(new byte[] {0x22})
     79                         .addCertificate(new byte[] {0x33})
     80                         .setOcspDataEmpty()
     81                         .setTlsSctDataEmpty()
     82                         .build());
     83     }
     84 
     85     @Test
     86     public void buildsInvalidOcspAndTlsSctSession() {
     87         assertArrayEquals(
     88                 new byte[] {
     89                         0x00, 0x00, 0x00, 0x11, 0x00, 0x33, 0x22, 0x11, 0x22, 0x12, 0x11, 0x22,
     90                         0x34, 0x10, 0x20, 0x30, 0x40, 0x33, 0x38, 0x48, 0x18, 0x28, 0x13, 0x24,
     91                         0x57, 0x68, 0x44, (byte) 0x99, (byte) 0x88, 0x77, 0x66, 0x55,
     92                 },
     93                 new TestSessionBuilder()
     94                         .setType(0x11)
     95                         .setSessionData(new byte[] {0x22})
     96                         .setSessionDataLength(0x332211)
     97                         .addCertificate(new byte[] {0x33})
     98                         .setCertificatesLength(0x12112234)
     99                         .setCertificateLength(0, 0x10203040)
    100                         .addOcspData(new byte[] {0x44})
    101                         .setOcspDatasLength(0x38481828)
    102                         .setOcspDataLength(0, 0x13245768)
    103                         .setTlsSctData(new byte[] {0x55})
    104                         .setTlsSctDataLength(0x99887766)
    105                         .build());
    106     }
    107 }
    108