Mercurial > hg > Applications > TightVNC_orginal
comparison src/main/java/com/glavsoft/rfb/protocol/auth/VncAuthentication.java @ 52:472a9bcacb21 draft default tip
TightVNC 2.7.1.0
author | you@cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 07 Aug 2013 19:01:17 +0900 |
parents | 4689cc86d6cb |
children |
comparison
equal
deleted
inserted
replaced
0:4689cc86d6cb | 52:472a9bcacb21 |
---|---|
1 // Copyright (C) 2010, 2011 GlavSoft LLC. | 1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 //------------------------------------------------------------------------- | 4 //------------------------------------------------------------------------- |
5 // This file is part of the TightVNC software. Please visit our Web site: | 5 // This file is part of the TightVNC software. Please visit our Web site: |
6 // | 6 // |
48 public boolean authenticate(Reader reader, | 48 public boolean authenticate(Reader reader, |
49 Writer writer, CapabilityContainer authCaps, IPasswordRetriever passwordRetriever) | 49 Writer writer, CapabilityContainer authCaps, IPasswordRetriever passwordRetriever) |
50 throws TransportException, FatalException { | 50 throws TransportException, FatalException { |
51 byte [] challenge = reader.readBytes(16); | 51 byte [] challenge = reader.readBytes(16); |
52 String password = passwordRetriever.getPassword(); | 52 String password = passwordRetriever.getPassword(); |
53 if (null == password) return false; | |
53 byte [] key = new byte[8]; | 54 byte [] key = new byte[8]; |
54 System.arraycopy(password.getBytes(), 0, key, 0, Math.min(key.length, password.getBytes().length)); | 55 System.arraycopy(password.getBytes(), 0, key, 0, Math.min(key.length, password.getBytes().length)); |
55 writer.write(encrypt(challenge, key)); | 56 writer.write(encrypt(challenge, key)); |
56 return false; | 57 return false; |
57 } | 58 } |
58 | 59 |
59 /** | 60 /** |
60 * Encript challenge by key using DES | 61 * Encript challenge by key using DES |
61 * @param challenge | |
62 * @param key | |
63 * @return encripted bytes | 62 * @return encripted bytes |
64 * @throws CryptoException on problem with DES algorithm support or smth about | 63 * @throws CryptoException on problem with DES algorithm support or smth about |
65 */ | 64 */ |
66 public byte[] encrypt(byte[] challenge, byte[] key) throws CryptoException { | 65 public byte[] encrypt(byte[] challenge, byte[] key) throws CryptoException { |
67 try { | 66 try { |
68 DESKeySpec desKeySpec = new DESKeySpec(mirrorBits(key)); | 67 DESKeySpec desKeySpec = new DESKeySpec(mirrorBits(key)); |
69 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); | 68 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); |
70 SecretKey secretKey = keyFactory.generateSecret(desKeySpec); | 69 SecretKey secretKey = keyFactory.generateSecret(desKeySpec); |
71 Cipher desCipher = Cipher.getInstance("DES/ECB/NoPadding"); | 70 Cipher desCipher = Cipher.getInstance("DES/ECB/NoPadding"); |
72 desCipher.init(Cipher.ENCRYPT_MODE, secretKey); | 71 desCipher.init(Cipher.ENCRYPT_MODE, secretKey); |
73 byte[] textEncrypted = desCipher.doFinal(challenge); | 72 return desCipher.doFinal(challenge); |
74 return textEncrypted; | |
75 } catch (NoSuchAlgorithmException e) { | 73 } catch (NoSuchAlgorithmException e) { |
76 throw new CryptoException("Cannot encrypt challenge", e); | 74 throw new CryptoException("Cannot encrypt challenge", e); |
77 } catch (NoSuchPaddingException e) { | 75 } catch (NoSuchPaddingException e) { |
78 throw new CryptoException("Cannot encrypt challenge", e); | 76 throw new CryptoException("Cannot encrypt challenge", e); |
79 } catch (IllegalBlockSizeException e) { | 77 } catch (IllegalBlockSizeException e) { |