OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [javax/] [net/] [ssl/] [provider/] [ClientHelloV2.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* ClientHelloV2.java -- a hello message from SSLv2.
2
   Copyright (C) 2006  Free Software Foundation, Inc.
3
 
4
This file is a part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at
9
your option) any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
USA
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
37
 
38
 
39
package gnu.javax.net.ssl.provider;
40
 
41
import java.io.PrintWriter;
42
import java.io.StringWriter;
43
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
45
import java.util.ArrayList;
46
import java.util.List;
47
 
48
/**
49
 * A client hello message from SSLv2. In SSLv3 and later, clients can
50
 * send an SSLv2 client hello message, but set the protocol version
51
 * for a later version.
52
 *
53
 * <p>The format of a version 2 client hello is:
54
 *
55
 * <pre>
56
    char MSG-CLIENT-HELLO          // equals 1
57
    char CLIENT-VERSION-MSB
58
    char CLIENT-VERSION-LSB
59
    char CIPHER-SPECS-LENGTH-MSB
60
    char CIPHER-SPECS-LENGTH-LSB
61
    char SESSION-ID-LENGTH-MSB
62
    char SESSION-ID-LENGTH-LSB
63
    char CHALLENGE-LENGTH-MSB
64
    char CHALLENGE-LENGTH-LSB
65
    char CIPHER-SPECS-DATA[(MSB&lt;&lt;8)|LSB]
66
    char SESSION-ID-DATA[(MSB&lt;&lt;8)|LSB]
67
    char CHALLENGE-DATA[(MSB&lt;&lt;8)|LSB]</pre>
68
 */
69
class ClientHelloV2 implements Constructed
70
{
71
  private final ByteBuffer buffer;
72
 
73
  ClientHelloV2 (final ByteBuffer buffer)
74
  {
75
    this.buffer = buffer.duplicate().order(ByteOrder.BIG_ENDIAN);
76
  }
77
 
78
  public int length ()
79
  {
80
    return 9 + cipherSpecsLength () + sessionIdLength () + challengeLength ();
81
  }
82
 
83
  ProtocolVersion version ()
84
  {
85
    return ProtocolVersion.getInstance (buffer.getShort (1));
86
  }
87
 
88
  int cipherSpecsLength ()
89
  {
90
    return buffer.getShort (3) & 0xFFFF;
91
  }
92
 
93
  int sessionIdLength ()
94
  {
95
    return buffer.getShort (5) & 0xFFFF;
96
  }
97
 
98
  int challengeLength ()
99
  {
100
    return buffer.getShort (7) & 0xFFFF;
101
  }
102
 
103
  public List<CipherSuite> cipherSpecs ()
104
  {
105
    int n = cipherSpecsLength ();
106
    List<CipherSuite> l = new ArrayList<CipherSuite>(n / 3);
107
    ByteBuffer b = (ByteBuffer) buffer.duplicate ().position (9);
108
    for (int i = 0; i < n; i += 3)
109
      {
110
        if (b.get () == 0)
111
          l.add (CipherSuite.forValue(b.getShort()).resolve());
112
        else
113
          b.getShort ();
114
      }
115
    return l;
116
  }
117
 
118
  byte[] sessionId ()
119
  {
120
    byte[] id = new byte[sessionIdLength ()];
121
    ((ByteBuffer) buffer.duplicate ().position (9 + cipherSpecsLength ())).get (id);
122
    return id;
123
  }
124
 
125
  byte[] challenge ()
126
  {
127
    byte[] challenge = new byte[challengeLength ()];
128
    ((ByteBuffer) buffer.duplicate ().position (9 + cipherSpecsLength () + sessionIdLength ())).get (challenge);
129
    return challenge;
130
  }
131
 
132
  public String toString ()
133
  {
134
    return toString (null);
135
  }
136
 
137
  public String toString (String prefix)
138
  {
139
    StringWriter str = new StringWriter ();
140
    PrintWriter out = new PrintWriter (str);
141
 
142
    if (prefix != null) out.print (prefix);
143
    out.println ("CLIENT-HELLO-MSG");
144
    if (prefix != null) out.print (prefix);
145
    out.print ("  version: ");
146
    out.println (version ());
147
    if (prefix != null) out.print (prefix);
148
    out.println ("  suites: ");
149
    out.println (cipherSpecs ());
150
    if (prefix != null) out.print (prefix);
151
    out.print ("  sessionId: ");
152
    out.println (Util.toHexString (sessionId (), ':'));
153
    if (prefix != null) out.print (prefix);
154
    out.print ("  challenge: ");
155
    out.println (Util.toHexString (challenge (), ':'));
156
    return str.toString ();
157
  }
158
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.