├── ico ├── Exposed_Conscious.png └── MainInterfaceIcon.png ├── .idea ├── vcs.xml ├── misc.xml ├── compiler.xml ├── modules.xml ├── libraries │ ├── net_i2p_i2p_0_9_35.xml │ ├── com_h2database_h2_1_4_197.xml │ ├── net_i2p_client_streaming_0_9_35.xml │ └── org_whispersystems_signal_protocol_java_2_6_2.xml └── uiDesigner.xml ├── src └── net │ ├── strangled │ └── maladan │ │ ├── serializables │ │ ├── Messaging │ │ │ ├── FileConstants.java │ │ │ ├── IEncryptedMessage.java │ │ │ ├── EncryptedFileEnd.java │ │ │ ├── EncryptedFileSpan.java │ │ │ ├── EncryptedFileInitiation.java │ │ │ ├── EncryptedMMessageObject.java │ │ │ ├── FileEnd.java │ │ │ ├── FileSpan.java │ │ │ ├── MMessageObject.java │ │ │ └── FileInitiation.java │ │ └── Authentication │ │ │ ├── IEncryptedAuth.java │ │ │ ├── UserExistsState.java │ │ │ ├── RegistrationResponseState.java │ │ │ ├── EncryptedRegistrationResponseState.java │ │ │ ├── LoginResponseState.java │ │ │ ├── EncryptedUser.java │ │ │ ├── EncryptedLoginResponseState.java │ │ │ ├── User.java │ │ │ ├── EncryptedClientPreKeyBundle.java │ │ │ ├── SignalEncryptedPasswordSend.java │ │ │ ├── ServerLogin.java │ │ │ └── ServerInit.java │ │ ├── shared │ │ ├── AuthResults.java │ │ ├── Contact.java │ │ ├── MessengerConversation.java │ │ ├── OutgoingMessageThread.java │ │ ├── LocalLoginDataStore.java │ │ └── IncomingMessageThread.java │ │ └── cli │ │ ├── MessageHandlerThread.java │ │ └── Main.java │ └── MaladaN │ └── Tor │ └── thoughtcrime │ ├── PreKeyPublic.java │ ├── InitData.java │ ├── ServerResponsePreKeyBundle.java │ ├── InitStore.java │ ├── SendInitData.java │ ├── GetSQLConnection.java │ ├── SignalCrypto.java │ └── MySignalProtocolStore.java ├── MaladaN-Messenger-Client.iml ├── README.md └── LICENSE /ico/Exposed_Conscious.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaladaN/MaladaN-Messenger-Client/HEAD/ico/Exposed_Conscious.png -------------------------------------------------------------------------------- /ico/MainInterfaceIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaladaN/MaladaN-Messenger-Client/HEAD/ico/MainInterfaceIcon.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/FileConstants.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class FileConstants { 4 | public static int bufferLength = 8192; 5 | public static int encryptionBufferLength = 16000; 6 | } 7 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/IEncryptedMessage.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public interface IEncryptedMessage { 4 | 5 | void storeEncryptedMessage(byte[] message); 6 | 7 | byte[] getEncryptedMessage(); 8 | } 9 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/IEncryptedAuth.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public interface IEncryptedAuth { 4 | 5 | void storeEncryptedData(byte[] encryptedData); 6 | 7 | byte[] getEncryptedData(); 8 | } 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/net_i2p_i2p_0_9_35.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/com_h2database_h2_1_4_197.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/UserExistsState.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | 4 | public class UserExistsState implements java.io.Serializable { 5 | 6 | private boolean userExists; 7 | 8 | public UserExistsState(boolean userExists) { 9 | this.userExists = userExists; 10 | } 11 | 12 | public boolean doesUserExists() { 13 | return userExists; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/RegistrationResponseState.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public class RegistrationResponseState implements java.io.Serializable { 4 | private boolean validRegistration; 5 | 6 | public RegistrationResponseState(boolean validRegistration) { 7 | this.validRegistration = validRegistration; 8 | } 9 | 10 | public boolean isValidRegistration() { 11 | return validRegistration; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/shared/AuthResults.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.shared; 2 | 3 | 4 | public class AuthResults { 5 | 6 | private String formattedResults; 7 | private boolean valid; 8 | 9 | AuthResults(String formattedResults, boolean valid) { 10 | this.formattedResults = formattedResults; 11 | this.valid = valid; 12 | } 13 | 14 | public String getFormattedResults() { 15 | return formattedResults; 16 | } 17 | 18 | public boolean isValid() { 19 | return valid; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/EncryptedFileEnd.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class EncryptedFileEnd implements java.io.Serializable, IEncryptedMessage { 4 | 5 | private byte[] serializedEncryptedFileEnd; 6 | 7 | @Override 8 | public void storeEncryptedMessage(byte[] message) { 9 | this.serializedEncryptedFileEnd = message; 10 | } 11 | 12 | @Override 13 | public byte[] getEncryptedMessage() { 14 | return this.serializedEncryptedFileEnd; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/EncryptedRegistrationResponseState.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public class EncryptedRegistrationResponseState implements java.io.Serializable, IEncryptedAuth { 4 | private byte[] encryptedState; 5 | 6 | @Override 7 | public void storeEncryptedData(byte[] encryptedData) { 8 | this.encryptedState = encryptedData; 9 | } 10 | 11 | @Override 12 | public byte[] getEncryptedData() { 13 | return this.encryptedState; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/LoginResponseState.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | 4 | public class LoginResponseState implements java.io.Serializable { 5 | //Sent to the client by the server, to tell the client the current authentication state. 6 | 7 | private boolean validLogin; 8 | 9 | public LoginResponseState(boolean validLogin) { 10 | this.validLogin = validLogin; 11 | } 12 | 13 | public boolean isValidLogin() { 14 | return validLogin; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/EncryptedFileSpan.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class EncryptedFileSpan implements java.io.Serializable, IEncryptedMessage { 4 | 5 | private byte[] serializedEncryptedFileSpan; 6 | 7 | @Override 8 | public void storeEncryptedMessage(byte[] message) { 9 | this.serializedEncryptedFileSpan = message; 10 | } 11 | 12 | @Override 13 | public byte[] getEncryptedMessage() { 14 | return this.serializedEncryptedFileSpan; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/shared/Contact.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.shared; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class Contact { 6 | 7 | private String username; 8 | private LinkedList messages; 9 | 10 | public Contact(String username, LinkedList messages) { 11 | this.username = username; 12 | this.messages = messages; 13 | } 14 | 15 | public String getUsername() { 16 | return username; 17 | } 18 | 19 | public LinkedList getMessages() { 20 | return messages; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/EncryptedFileInitiation.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class EncryptedFileInitiation implements java.io.Serializable, IEncryptedMessage { 4 | 5 | private byte[] serializedEncryptedFileInitiation; 6 | 7 | @Override 8 | public void storeEncryptedMessage(byte[] message) { 9 | this.serializedEncryptedFileInitiation = message; 10 | } 11 | 12 | @Override 13 | public byte[] getEncryptedMessage() { 14 | return serializedEncryptedFileInitiation; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/EncryptedUser.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public class EncryptedUser implements java.io.Serializable, IEncryptedAuth { 4 | //Stored encrypted User class 5 | 6 | private byte[] encryptedSerializedUser; 7 | 8 | @Override 9 | public void storeEncryptedData(byte[] encryptedData) { 10 | this.encryptedSerializedUser = encryptedData; 11 | } 12 | 13 | @Override 14 | public byte[] getEncryptedData() { 15 | return this.encryptedSerializedUser; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/EncryptedLoginResponseState.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public class EncryptedLoginResponseState implements java.io.Serializable, IEncryptedAuth { 4 | //Holds the login State for transport 5 | 6 | private byte[] encryptedState; 7 | 8 | @Override 9 | public void storeEncryptedData(byte[] encryptedData) { 10 | this.encryptedState = encryptedData; 11 | } 12 | 13 | @Override 14 | public byte[] getEncryptedData() { 15 | return encryptedState; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.idea/libraries/net_i2p_client_streaming_0_9_35.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/User.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | 4 | public class User implements java.io.Serializable { 5 | //Used by the server to keep track of sessions. 6 | 7 | private boolean loggedIn; 8 | private String username; 9 | 10 | public User(boolean loggedIn, String username) { 11 | this.loggedIn = loggedIn; 12 | this.username = username; 13 | } 14 | 15 | public boolean isLoggedIn() { 16 | return loggedIn; 17 | } 18 | 19 | public String getUsername() { 20 | return username; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/EncryptedMMessageObject.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class EncryptedMMessageObject implements java.io.Serializable, IEncryptedMessage { 4 | //Stores encrypted MMessageObject class 5 | 6 | private byte[] encryptedSerializedMMessageObject; 7 | 8 | @Override 9 | public void storeEncryptedMessage(byte[] message) { 10 | this.encryptedSerializedMMessageObject = message; 11 | } 12 | 13 | @Override 14 | public byte[] getEncryptedMessage() { 15 | return this.encryptedSerializedMMessageObject; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/EncryptedClientPreKeyBundle.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public class EncryptedClientPreKeyBundle implements java.io.Serializable, IEncryptedAuth { 4 | //stores an encrypted client pre key bundle for transport 5 | 6 | private byte[] encryptedSerializedClientPreKeyBundle; 7 | 8 | @Override 9 | public void storeEncryptedData(byte[] encryptedData) { 10 | this.encryptedSerializedClientPreKeyBundle = encryptedData; 11 | } 12 | 13 | @Override 14 | public byte[] getEncryptedData() { 15 | return this.encryptedSerializedClientPreKeyBundle; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/FileEnd.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class FileEnd implements java.io.Serializable { 4 | 5 | private String destinationBase64Username; 6 | private byte[] encryptedFileBuffer; 7 | 8 | public FileEnd(String destinationBase64Username, byte[] encryptedFileBuffer) { 9 | this.destinationBase64Username = destinationBase64Username; 10 | this.encryptedFileBuffer = encryptedFileBuffer; 11 | } 12 | 13 | public String getDestinationBase64Username() { 14 | return destinationBase64Username; 15 | } 16 | 17 | public byte[] getEncryptedFileBuffer() { 18 | return encryptedFileBuffer; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/FileSpan.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class FileSpan implements java.io.Serializable { 4 | 5 | private String destinationBase64Username; 6 | private byte[] encryptedFileBuffer; 7 | 8 | public FileSpan(String destinationBase64Username, byte[] encryptedFileBuffer) { 9 | this.destinationBase64Username = destinationBase64Username; 10 | this.encryptedFileBuffer = encryptedFileBuffer; 11 | } 12 | 13 | public String getDestinationBase64Username() { 14 | return destinationBase64Username; 15 | } 16 | 17 | public byte[] getEncryptedFileBuffer() { 18 | return encryptedFileBuffer; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MaladaN-Messenger-Client.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/SignalEncryptedPasswordSend.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | public class SignalEncryptedPasswordSend implements java.io.Serializable { 4 | //Used to send the password for a new account, after it has been created using ServerInit. 5 | //Password comes in encrypted using the signal protocol. 6 | 7 | private byte[] serializedPassword; 8 | private String username; 9 | 10 | public SignalEncryptedPasswordSend(byte[] serializedPassword, String username) { 11 | this.serializedPassword = serializedPassword; 12 | this.username = username; 13 | } 14 | 15 | public byte[] getSerializedPassword() { 16 | return serializedPassword; 17 | } 18 | 19 | public String getUsername() { 20 | return username; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/shared/MessengerConversation.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.shared; 2 | 3 | public class MessengerConversation { 4 | private String contactName; 5 | private String contactPhotoPath = "./MainInterfaceIcon.png"; 6 | 7 | public MessengerConversation(String contactName, String contactPhotoPath) { 8 | this.contactName = contactName; 9 | this.contactPhotoPath = contactPhotoPath; 10 | } 11 | 12 | public String getContactName() { 13 | return contactName; 14 | } 15 | 16 | public void setContactName(String contactName) { 17 | this.contactName = contactName; 18 | } 19 | 20 | public String getContactPhotoPath() { 21 | return contactPhotoPath; 22 | } 23 | 24 | public void setContactPhotoPath(String contactPhotoPath) { 25 | this.contactPhotoPath = contactPhotoPath; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/MMessageObject.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class MMessageObject implements java.io.Serializable { 4 | private byte[] serializedMessageObject; 5 | private String destinationUser; 6 | private String sendingUser; 7 | 8 | public MMessageObject(byte[] serializedMessageObject, String destinationUser, String sendingUser) { 9 | this.serializedMessageObject = serializedMessageObject; 10 | this.destinationUser = destinationUser; 11 | this.sendingUser = sendingUser; 12 | } 13 | 14 | public byte[] getSerializedMessageObject() { 15 | return serializedMessageObject; 16 | } 17 | 18 | public String getDestinationUser() { 19 | return destinationUser; 20 | } 21 | 22 | public String getSendingUser() { 23 | return sendingUser; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/PreKeyPublic.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | 4 | import org.whispersystems.libsignal.ecc.Curve; 5 | import org.whispersystems.libsignal.ecc.ECPublicKey; 6 | 7 | public class PreKeyPublic implements java.io.Serializable { 8 | private byte[] preKeyPublic; 9 | private int prekeyId; 10 | 11 | public PreKeyPublic(ECPublicKey preKeyPublic, int prekeyId) { 12 | this.preKeyPublic = preKeyPublic.serialize(); 13 | this.prekeyId = prekeyId; 14 | } 15 | 16 | public ECPublicKey getPreKeyPublic() { 17 | ECPublicKey publicKey = null; 18 | try { 19 | publicKey = Curve.decodePoint(preKeyPublic, 0); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | return publicKey; 24 | } 25 | 26 | public int getPrekeyId() { 27 | return prekeyId; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/ServerLogin.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | 4 | public class ServerLogin implements java.io.Serializable { 5 | //Used by the client to login to the server 6 | 7 | private String username; 8 | private byte[] serializedIdentityKey; 9 | private byte[] encryptedPassword; 10 | 11 | public ServerLogin(String encodedHashedUsername, byte[] encryptedPassword, byte[] serializedIdentityKey) { 12 | username = encodedHashedUsername; 13 | this.encryptedPassword = encryptedPassword; 14 | this.serializedIdentityKey = serializedIdentityKey; 15 | } 16 | 17 | public String getUsername() { 18 | return username; 19 | } 20 | 21 | public byte[] getEncryptedPassword() { 22 | return encryptedPassword; 23 | } 24 | 25 | public byte[] getSerializedIdentityKey() { 26 | return serializedIdentityKey; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/InitData.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | import org.whispersystems.libsignal.state.PreKeyRecord; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | 9 | public class InitData { 10 | private int signedPreKeyId; 11 | private List preKeyRecords; 12 | 13 | public InitData(int signedPreKeyId, List preKeyRecords) { 14 | saveData(signedPreKeyId, preKeyRecords); 15 | } 16 | 17 | public void saveData(int signedPreKeyId, List preKeyRecords) { 18 | if (signedPreKeyId != 0 && preKeyRecords != null) { 19 | this.signedPreKeyId = signedPreKeyId; 20 | this.preKeyRecords = preKeyRecords; 21 | } 22 | } 23 | 24 | public List getPreKeyRecords() { 25 | List records = new ArrayList<>(); 26 | records.addAll(this.preKeyRecords); 27 | return records; 28 | } 29 | 30 | public int getSignedPreKeyId() { 31 | return this.signedPreKeyId; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.idea/libraries/org_whispersystems_signal_protocol_java_2_6_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Messaging/FileInitiation.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Messaging; 2 | 3 | public class FileInitiation implements java.io.Serializable { 4 | 5 | private long fileLengthInBytes; 6 | private String base64Username; 7 | private String destinationBase64Username; 8 | 9 | private byte[] encryptedInitialFileBuffer; 10 | 11 | public FileInitiation(long fileLengthInBytes, String base64Username, String destinationBase64Username, byte[] encryptedInitialFileBuffer) { 12 | this.fileLengthInBytes = fileLengthInBytes; 13 | this.base64Username = base64Username; 14 | this.destinationBase64Username = destinationBase64Username; 15 | this.encryptedInitialFileBuffer = encryptedInitialFileBuffer; 16 | } 17 | 18 | public long getFileLengthInBytes() { 19 | return fileLengthInBytes; 20 | } 21 | 22 | public String getBase64Username() { 23 | return base64Username; 24 | } 25 | 26 | public String getDestinationBase64Username() { 27 | return destinationBase64Username; 28 | } 29 | 30 | public byte[] getEncryptedInitialFileBuffer() { 31 | return encryptedInitialFileBuffer; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MaladaN-Messenger 2 | An end to end encrypted Messenger that uses the signal protocol over the I2P network 3 | 4 | Development IDE: Intellij IDEA 5 | 6 | # Required Libraries: 7 | com.h2database:h2:1.4.197 8 | 9 | net.i2p.client:streaming:0.9.35 10 | 11 | net.i2p:i2p:0.9.35 12 | 13 | org.whispersystems:signal-protocol-java:2.6.2 14 | 15 | # Legal things 16 | Cryptography Notice 17 | 18 | This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See http://www.wassenaar.org/ for more information. 19 | 20 | The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code. 21 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/ServerResponsePreKeyBundle.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | import org.whispersystems.libsignal.IdentityKey; 4 | import org.whispersystems.libsignal.ecc.Curve; 5 | import org.whispersystems.libsignal.state.PreKeyBundle; 6 | 7 | public class ServerResponsePreKeyBundle implements java.io.Serializable { 8 | //got this. 9 | private int registrationId; 10 | private PreKeyPublic preKey = null; 11 | private int signedPreKeyId; 12 | private byte[] signedPreKeyPublic; 13 | private byte[] signedPreKeySignature; 14 | private byte[] identityKey; 15 | 16 | //deviceId not present, only one device. 17 | 18 | public ServerResponsePreKeyBundle(int registrationId, PreKeyPublic preKey, int signedPreKeyId, byte[] signedPreKeyPublic, byte[] signedPreKeySignature, byte[] identityKey) { 19 | this.registrationId = registrationId; 20 | this.preKey = preKey; 21 | this.signedPreKeyId = signedPreKeyId; 22 | this.signedPreKeyPublic = signedPreKeyPublic; 23 | this.signedPreKeySignature = signedPreKeySignature; 24 | this.identityKey = identityKey; 25 | } 26 | 27 | public PreKeyBundle getPreKeyBundle() { 28 | try { 29 | return new PreKeyBundle(registrationId, 0, preKey.getPrekeyId(), preKey.getPreKeyPublic(), this.signedPreKeyId, Curve.decodePoint(this.signedPreKeyPublic, 0), this.signedPreKeySignature, new IdentityKey(identityKey, 0)); 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | return null; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/cli/MessageHandlerThread.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.cli; 2 | 3 | 4 | import net.MaladaN.Tor.thoughtcrime.SignalCrypto; 5 | import net.strangled.maladan.serializables.Messaging.MMessageObject; 6 | import net.strangled.maladan.shared.IncomingMessageThread; 7 | import org.whispersystems.libsignal.SignalProtocolAddress; 8 | 9 | import java.util.List; 10 | 11 | public class MessageHandlerThread implements Runnable { 12 | 13 | private boolean running = true; 14 | private Thread t; 15 | 16 | @Override 17 | public void run() { 18 | while (running) { 19 | List objects; 20 | 21 | try { 22 | Thread.sleep(600); 23 | } catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | 27 | objects = IncomingMessageThread.getIncomingMessages(); 28 | 29 | if (!objects.isEmpty()) { 30 | 31 | for (MMessageObject object : objects) { 32 | byte[] encryptedMessage = object.getSerializedMessageObject(); 33 | String decryptedMessage = SignalCrypto.decryptStringMessage(encryptedMessage, new SignalProtocolAddress(object.getSendingUser(), 0)); 34 | System.out.println(decryptedMessage); 35 | } 36 | 37 | IncomingMessageThread.deleteMessageObjects(objects); 38 | } 39 | 40 | } 41 | } 42 | 43 | void shutdown() { 44 | running = false; 45 | } 46 | 47 | void start() { 48 | if (t == null) { 49 | t = new Thread(this); 50 | t.start(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/shared/OutgoingMessageThread.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.shared; 2 | 3 | 4 | import java.io.ObjectOutputStream; 5 | import java.io.OutputStream; 6 | import java.util.LinkedList; 7 | import java.util.Vector; 8 | 9 | public class OutgoingMessageThread implements Runnable { 10 | 11 | public static boolean running = true; 12 | private static Vector outgoingMessages = new Vector<>(); 13 | private Thread t; 14 | private OutputStream stream; 15 | 16 | public OutgoingMessageThread(OutputStream stream) { 17 | this.stream = stream; 18 | } 19 | 20 | public static synchronized void addOutgoingMessage(Object message) { 21 | outgoingMessages.add(message); 22 | } 23 | 24 | @Override 25 | public void run() { 26 | 27 | try { 28 | ObjectOutputStream out = new ObjectOutputStream(stream); 29 | 30 | while (running) { 31 | Thread.sleep(5); 32 | 33 | if (!outgoingMessages.isEmpty()) { 34 | LinkedList currentOut = new LinkedList<>(); 35 | currentOut.addAll(outgoingMessages); 36 | 37 | for (Object j : currentOut) { 38 | out.writeObject(j); 39 | Thread.sleep(2); 40 | out.flush(); 41 | } 42 | outgoingMessages.removeAll(currentOut); 43 | } 44 | } 45 | 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | public void start() { 52 | if (t == null) { 53 | t = new Thread(this); 54 | t.start(); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/serializables/Authentication/ServerInit.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.serializables.Authentication; 2 | 3 | 4 | import net.MaladaN.Tor.thoughtcrime.InitData; 5 | import net.MaladaN.Tor.thoughtcrime.MySignalProtocolStore; 6 | import net.MaladaN.Tor.thoughtcrime.SendInitData; 7 | import org.whispersystems.libsignal.InvalidKeyIdException; 8 | import org.whispersystems.libsignal.state.SignalProtocolStore; 9 | 10 | public class ServerInit implements java.io.Serializable { 11 | //Used to initiate an account with the server, by the client. 12 | 13 | //username is a SHA-256 hash of the username passed by the user 14 | //which is then turned into a base64 representation. 15 | private String username; 16 | private SendInitData initData; 17 | private boolean isNewUser; 18 | 19 | //only used for initial registration 20 | private String uniqueId; 21 | 22 | public ServerInit(String username, String uniqueId, InitData data) throws InvalidKeyIdException { 23 | SignalProtocolStore store = new MySignalProtocolStore(); 24 | this.username = username; 25 | this.uniqueId = uniqueId; 26 | if ((isNewUser = (data != null))) { 27 | this.initData = new SendInitData(store.getLocalRegistrationId(), data.getPreKeyRecords(), store.loadSignedPreKey(data.getSignedPreKeyId()), store.getIdentityKeyPair().getPublicKey()); 28 | } 29 | isNewUser = (uniqueId != null); 30 | } 31 | 32 | public String getUsername() { 33 | return username; 34 | } 35 | 36 | public SendInitData getInitData() { 37 | return initData; 38 | } 39 | 40 | public boolean isNewUser() { 41 | return isNewUser; 42 | } 43 | 44 | public String getUniqueId() { 45 | return uniqueId; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/shared/LocalLoginDataStore.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.shared; 2 | 3 | import net.MaladaN.Tor.thoughtcrime.GetSQLConnection; 4 | import net.strangled.maladan.cli.Main; 5 | import net.strangled.maladan.serializables.Authentication.User; 6 | 7 | import java.sql.Connection; 8 | import java.sql.PreparedStatement; 9 | import java.sql.ResultSet; 10 | 11 | public class LocalLoginDataStore { 12 | 13 | public static void saveLocaluser(User user) throws Exception { 14 | Connection conn = GetSQLConnection.getConn(); 15 | 16 | if (conn != null && !dataSaved()) { 17 | String sql = "INSERT INTO username (user) VALUES (?)"; 18 | PreparedStatement ps = conn.prepareStatement(sql); 19 | ps.setBytes(1, Main.serializeObject(user)); 20 | ps.execute(); 21 | conn.close(); 22 | } 23 | } 24 | 25 | public static boolean dataSaved() throws Exception { 26 | Connection conn = GetSQLConnection.getConn(); 27 | 28 | if (conn != null) { 29 | String sql = "SELECT user FROM username"; 30 | PreparedStatement ps = conn.prepareStatement(sql); 31 | ResultSet rs = ps.executeQuery(); 32 | boolean exists = rs.next(); 33 | conn.close(); 34 | return exists; 35 | 36 | } 37 | return false; 38 | } 39 | 40 | public static User getData() throws Exception { 41 | Connection conn = GetSQLConnection.getConn(); 42 | 43 | if (conn != null) { 44 | String sql = "SELECT user FROM username"; 45 | PreparedStatement ps = conn.prepareStatement(sql); 46 | ResultSet rs = ps.executeQuery(); 47 | rs.next(); 48 | byte[] serializedUser = rs.getBytes("user"); 49 | conn.close(); 50 | return (User) Main.reconstructSerializedObject(serializedUser); 51 | } 52 | return null; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/InitStore.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | 4 | import org.whispersystems.libsignal.IdentityKeyPair; 5 | 6 | import java.sql.Connection; 7 | import java.sql.PreparedStatement; 8 | import java.sql.ResultSet; 9 | 10 | class InitStore { 11 | static void storeIdentityKeyPairAndRegistrationId(IdentityKeyPair identityKeyPair, int localRegistrationId) { 12 | Connection conn = GetSQLConnection.getConn(); 13 | if (conn != null) { 14 | String sql = "INSERT INTO localIdentityStorage (identityKeyPair, localRegistrationId) VALUES (?, ?)"; 15 | try { 16 | PreparedStatement ps = conn.prepareStatement(sql); 17 | ps.setBytes(1, identityKeyPair.serialize()); 18 | ps.setInt(2, localRegistrationId); 19 | ps.execute(); 20 | conn.close(); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | } 26 | 27 | static void setInstalledFlagTrue() { 28 | Connection conn = GetSQLConnection.getConn(); 29 | if (conn != null) { 30 | String sql = "INSERT INTO installedFlag (flag) VALUES (1)"; 31 | try { 32 | PreparedStatement ps = conn.prepareStatement(sql); 33 | ps.execute(); 34 | conn.close(); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | 41 | static boolean isInstalled() { 42 | Connection conn = GetSQLConnection.getConn(); 43 | if (conn != null) { 44 | String sql = "SELECT flag FROM installedFlag"; 45 | try { 46 | PreparedStatement ps = conn.prepareStatement(sql); 47 | ResultSet rs = ps.executeQuery(); 48 | if (rs.next()) { 49 | int flag = rs.getInt("flag"); 50 | conn.close(); 51 | return (flag == 1); 52 | } else { 53 | conn.close(); 54 | return false; 55 | } 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/SendInitData.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | 4 | import org.whispersystems.libsignal.IdentityKey; 5 | import org.whispersystems.libsignal.state.PreKeyRecord; 6 | import org.whispersystems.libsignal.state.SignedPreKeyRecord; 7 | 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | import java.util.concurrent.ThreadLocalRandom; 11 | 12 | public class SendInitData implements java.io.Serializable { 13 | private int registrationId; 14 | private List preKeys = new LinkedList<>(); 15 | private int signedPreKeyId; 16 | private byte[] signedPreKeyPublic; 17 | private byte[] signedPreKeySignature; 18 | private byte[] identityKey; 19 | 20 | public SendInitData(int registrationId, List preKeys, SignedPreKeyRecord signedPreKey, IdentityKey identityKey) { 21 | if (registrationId != 0 && identityKey != null) { 22 | this.registrationId = registrationId; 23 | 24 | //add the temporary pre keys (deleted by the server on use) 25 | addPreKeys(preKeys); 26 | 27 | //add the signed pre key (changed on a weekly basis) 28 | updateSignedPreKey(signedPreKey); 29 | 30 | this.identityKey = identityKey.serialize(); 31 | } 32 | } 33 | 34 | public void updateSignedPreKey(SignedPreKeyRecord signedPreKey) { 35 | if (signedPreKey != null) { 36 | this.signedPreKeyId = signedPreKey.getId(); 37 | this.signedPreKeyPublic = signedPreKey.getKeyPair().getPublicKey().serialize(); 38 | this.signedPreKeySignature = signedPreKey.getSignature(); 39 | } 40 | } 41 | 42 | public void addPreKeys(List preKeys) { 43 | if (preKeys != null) { 44 | this.preKeys.clear(); 45 | 46 | for (PreKeyRecord record : preKeys) { 47 | this.preKeys.add(new PreKeyPublic(record.getKeyPair().getPublicKey(), record.getId())); 48 | } 49 | } 50 | } 51 | 52 | public int getNumberOfPreKeys() { 53 | return this.preKeys.size(); 54 | } 55 | 56 | public ServerResponsePreKeyBundle getServerResponsePreKeyBundle() { 57 | int randomPreKeyIdPuller = ThreadLocalRandom.current().nextInt(0, preKeys.size()); 58 | 59 | try { 60 | PreKeyPublic recordToSend = preKeys.get(randomPreKeyIdPuller); 61 | preKeys.remove(randomPreKeyIdPuller); 62 | 63 | return new ServerResponsePreKeyBundle(registrationId, recordToSend, signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey); 64 | 65 | } catch (IndexOutOfBoundsException e) { 66 | return null; 67 | } 68 | } 69 | 70 | public IdentityKey getIdKey() throws Exception { 71 | return new IdentityKey(identityKey, 0); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/GetSQLConnection.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | 7 | public class GetSQLConnection { 8 | private static int initialFlag = 0; 9 | 10 | private static void setInitialFlag() { 11 | initialFlag = 1; 12 | } 13 | 14 | private static int getInitialFlag() { 15 | return initialFlag; 16 | } 17 | 18 | public static Connection getConn() { 19 | try { 20 | if (getInitialFlag() == 1) { 21 | Class.forName("org.h2.Driver"); 22 | return DriverManager. 23 | getConnection("jdbc:h2:./DB/M_DB", "Shinobu", "Oshino"); 24 | } else { 25 | setInitialFlag(); 26 | return initDBReturnConnection(); 27 | } 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | return null; 31 | } 32 | } 33 | 34 | private static Connection initDBReturnConnection() { 35 | try { 36 | Class.forName("org.h2.Driver"); 37 | Connection conn = DriverManager. 38 | getConnection("jdbc:h2:./DB/M_DB", "Shinobu", "Oshino"); 39 | 40 | String identityKeyStoreTable = "CREATE TABLE IF NOT EXISTS identityKeyStorage (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 41 | " identityKeypair longblob, localRegistrationId int(10), signalProtocolAddress VARCHAR(64), identityKey longblob, PRIMARY KEY (id))"; 42 | PreparedStatement ps = conn.prepareStatement(identityKeyStoreTable); 43 | ps.execute(); 44 | 45 | String localRegIdAndIdentity = "CREATE TABLE IF NOT EXISTS localIdentityStorage (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 46 | " identityKeyPair longblob, localRegistrationId int(10), PRIMARY KEY (id))"; 47 | ps = conn.prepareStatement(localRegIdAndIdentity); 48 | ps.execute(); 49 | 50 | String preKeyStoreTable = "CREATE TABLE IF NOT EXISTS preKeyStorage (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 51 | " preKeyRecord longblob, keyId int(10), PRIMARY KEY (id))"; 52 | ps = conn.prepareStatement(preKeyStoreTable); 53 | ps.execute(); 54 | 55 | String sessionStoreTable = "CREATE TABLE IF NOT EXISTS sessionStoreStorage (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 56 | " protocolAddress VARCHAR(64), sessionRecord longblob, PRIMARY KEY (id))"; 57 | ps = conn.prepareStatement(sessionStoreTable); 58 | ps.execute(); 59 | 60 | String signedPreKeyTable = "CREATE TABLE IF NOT EXISTS signedPreKeyStore (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 61 | " signedPreKeyRecord longblob, keyId int(10), PRIMARY KEY (id))"; 62 | ps = conn.prepareStatement(signedPreKeyTable); 63 | ps.execute(); 64 | 65 | String installedFlag = "CREATE TABLE IF NOT EXISTS installedFlag (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 66 | "flag int(10), PRIMARY KEY (id))"; 67 | ps = conn.prepareStatement(installedFlag); 68 | ps.execute(); 69 | 70 | //Local Username Storage 71 | String username = "CREATE TABLE IF NOT EXISTS username (id int(10) unsigned NOT NULL AUTO_INCREMENT," + 72 | "user longblob, PRIMARY KEY (id))"; 73 | ps = conn.prepareStatement(username); 74 | ps.execute(); 75 | 76 | return conn; 77 | } catch (Exception e) { 78 | e.printStackTrace(); 79 | return null; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/SignalCrypto.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | import org.whispersystems.libsignal.*; 4 | import org.whispersystems.libsignal.protocol.CiphertextMessage; 5 | import org.whispersystems.libsignal.protocol.PreKeySignalMessage; 6 | import org.whispersystems.libsignal.protocol.SignalMessage; 7 | import org.whispersystems.libsignal.state.*; 8 | import org.whispersystems.libsignal.util.KeyHelper; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class SignalCrypto { 14 | 15 | public static byte[] encryptByteMessage(byte[] message, SignalProtocolAddress address, PreKeyBundle bundle) { 16 | SignalProtocolStore protocolStore = new MySignalProtocolStore(); 17 | 18 | if (message != null) { 19 | 20 | if (!protocolStore.containsSession(address)) { 21 | 22 | if (bundle != null) { 23 | boolean valid = trustIdentity(address, bundle.getIdentityKey()); 24 | if (valid) { 25 | return encrypt(message, bundle, address); 26 | } 27 | } 28 | } else { 29 | return encrypt(message, address); 30 | } 31 | } 32 | return null; 33 | } 34 | 35 | private static boolean trustIdentity(SignalProtocolAddress address, IdentityKey key) { 36 | SignalProtocolStore protocolStore = new MySignalProtocolStore(); 37 | boolean contactedBefore = protocolStore.isTrustedIdentity(address, null, IdentityKeyStore.Direction.SENDING); 38 | boolean isAlreadyTrusted = protocolStore.isTrustedIdentity(address, key, IdentityKeyStore.Direction.SENDING); 39 | 40 | //can be expanded at a later time if necessary 41 | if (!contactedBefore && !isAlreadyTrusted) { 42 | protocolStore.saveIdentity(address, key); 43 | return true; 44 | } else { 45 | return isAlreadyTrusted; 46 | } 47 | } 48 | 49 | public static byte[] encryptStringMessage(String message, SignalProtocolAddress address, PreKeyBundle bundle) { 50 | //encrypt message 51 | byte[] byteString = null; 52 | try { 53 | byteString = message.getBytes("UTF-8"); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | return encryptByteMessage(byteString, address, bundle); 58 | } 59 | 60 | public static String decryptStringMessage(byte[] message, SignalProtocolAddress address) { 61 | try { 62 | byte[] cleartext = decryptMessage(message, address); 63 | if (cleartext != null) { 64 | return new String(cleartext, "UTF-8"); 65 | } 66 | } catch (Exception e) { 67 | e.printStackTrace(); 68 | } 69 | return null; 70 | } 71 | 72 | public static byte[] decryptMessage(byte[] message, SignalProtocolAddress address) { 73 | //decrypt message 74 | 75 | try { 76 | byte[] returned = decrypt(message, address); 77 | 78 | if (returned != null) { 79 | return returned; 80 | } 81 | } catch (Exception e) { 82 | e.printStackTrace(); 83 | } 84 | return null; 85 | } 86 | 87 | private static byte[] encrypt(byte[] message, PreKeyBundle preKeyBundle, SignalProtocolAddress signalProtocolAddress) { 88 | if (preKeyBundle != null) { 89 | getSession(signalProtocolAddress, preKeyBundle); 90 | } 91 | SessionCipher sessionCipher = new SessionCipher(new MySignalProtocolStore(), signalProtocolAddress); 92 | 93 | try { 94 | CiphertextMessage message1 = sessionCipher.encrypt(message); 95 | return message1.serialize(); 96 | } catch (Exception e) { 97 | e.printStackTrace(); 98 | } 99 | return null; 100 | } 101 | 102 | private static byte[] encrypt(byte[] message, SignalProtocolAddress address) { 103 | return encrypt(message, null, address); 104 | } 105 | 106 | private static byte[] decrypt(byte[] message, SignalProtocolAddress senderAddress) { 107 | SessionCipher sessionCipher = new SessionCipher(new MySignalProtocolStore(), senderAddress); 108 | PreKeySignalMessage pks; 109 | SignalMessage signalMessage; 110 | 111 | if (message != null) { 112 | try { 113 | pks = new PreKeySignalMessage(message); 114 | boolean valid = trustIdentity(senderAddress, pks.getIdentityKey()); 115 | if (valid) { 116 | return sessionCipher.decrypt(pks); 117 | } 118 | } catch (Exception e) { 119 | try { 120 | signalMessage = new SignalMessage(message); 121 | return sessionCipher.decrypt(signalMessage); 122 | } catch (Exception f) { 123 | e.printStackTrace(); 124 | f.printStackTrace(); 125 | } 126 | } 127 | } 128 | return null; 129 | } 130 | 131 | private static InitData init() { 132 | 133 | //create data 134 | IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair(); 135 | int registrationId = KeyHelper.generateRegistrationId(true); 136 | List preKeys = KeyHelper.generatePreKeys(2, 100); 137 | SignalProtocolStore signalProtocolStore = new MySignalProtocolStore(); 138 | 139 | ArrayList records = new ArrayList<>(); 140 | int id = 0; 141 | 142 | //store signed PreKey 143 | try { 144 | SignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 5); 145 | signalProtocolStore.storeSignedPreKey(signedPreKey.getId(), signedPreKey); 146 | id = signedPreKey.getId(); 147 | } catch (Exception e) { 148 | e.printStackTrace(); 149 | } 150 | 151 | //store required data as outlined in the documentation 152 | InitStore.storeIdentityKeyPairAndRegistrationId(identityKeyPair, registrationId); 153 | for (PreKeyRecord ps : preKeys) { 154 | signalProtocolStore.storePreKey(ps.getId(), ps); 155 | records.add(ps); 156 | } 157 | 158 | return new InitData(id, records); 159 | 160 | // Store identityKeyPair somewhere durable and safe. 161 | // Store registrationId somewhere durable and safe. 162 | 163 | // Store preKeys in PreKeyStore. 164 | // Store signed preKey in SignedPreKeyStore. 165 | } 166 | 167 | private static void getSession(SignalProtocolAddress address, PreKeyBundle preKeyBundle) { 168 | SignalProtocolStore signalProtocolStore = new MySignalProtocolStore(); 169 | 170 | // Instantiate a SessionBuilder for a remote recipientId + deviceId tuple. 171 | SessionBuilder sessionBuilder = new SessionBuilder(signalProtocolStore, 172 | address); 173 | 174 | // Build a session with a PreKey retrieved from the server. 175 | try { 176 | sessionBuilder.process(preKeyBundle); 177 | } catch (Exception e) { 178 | e.printStackTrace(); 179 | } 180 | } 181 | 182 | //MUST BE CALLED BEFORE TRYING TO DO ANYTHING 183 | public static InitData initStore() { 184 | if (!InitStore.isInstalled()) { 185 | InitData data = init(); 186 | InitStore.setInstalledFlagTrue(); 187 | return data; 188 | } 189 | return null; 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/shared/IncomingMessageThread.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.shared; 2 | 3 | 4 | import net.MaladaN.Tor.thoughtcrime.ServerResponsePreKeyBundle; 5 | import net.MaladaN.Tor.thoughtcrime.SignalCrypto; 6 | import net.strangled.maladan.cli.Main; 7 | import net.strangled.maladan.serializables.Authentication.*; 8 | import net.strangled.maladan.serializables.Messaging.EncryptedMMessageObject; 9 | import net.strangled.maladan.serializables.Messaging.MMessageObject; 10 | import org.whispersystems.libsignal.SignalProtocolAddress; 11 | import org.whispersystems.libsignal.state.PreKeyBundle; 12 | 13 | import java.io.InputStream; 14 | import java.io.ObjectInputStream; 15 | import java.util.List; 16 | import java.util.Vector; 17 | 18 | public class IncomingMessageThread implements Runnable { 19 | 20 | private static String password; 21 | private static String username; 22 | private static boolean registrationFlag; 23 | private static AuthResults loginResults = null; 24 | private static PreKeyBundle userBundle = null; 25 | private static Vector incomingMessages = new Vector<>(); 26 | public boolean running = true; 27 | private Thread t; 28 | private InputStream stream; 29 | 30 | 31 | public IncomingMessageThread(InputStream stream) { 32 | this.stream = stream; 33 | } 34 | 35 | public static synchronized void setCredentials(String password, String username) { 36 | IncomingMessageThread.password = password; 37 | IncomingMessageThread.username = username; 38 | registrationFlag = true; 39 | } 40 | 41 | public static synchronized AuthResults getAuthResults() { 42 | return IncomingMessageThread.loginResults; 43 | } 44 | 45 | public static synchronized void clearAuthResults() { 46 | IncomingMessageThread.loginResults = null; 47 | } 48 | 49 | public static synchronized PreKeyBundle getUserBundle() { 50 | return IncomingMessageThread.userBundle; 51 | } 52 | 53 | public static synchronized void setUserBundle(PreKeyBundle userBundle) { 54 | IncomingMessageThread.userBundle = userBundle; 55 | } 56 | 57 | public static synchronized List getIncomingMessages() { 58 | return new Vector<>(IncomingMessageThread.incomingMessages); 59 | } 60 | 61 | public static synchronized void deleteMessageObjects(List objectsToRemove) { 62 | IncomingMessageThread.incomingMessages.removeAll(objectsToRemove); 63 | } 64 | 65 | @Override 66 | public void run() { 67 | try { 68 | ObjectInputStream in = new ObjectInputStream(stream); 69 | 70 | while (running) { 71 | Object incoming = in.readObject(); 72 | 73 | if (incoming instanceof ServerResponsePreKeyBundle && registrationFlag) { 74 | ServerResponsePreKeyBundle serverResponsePreKeyBundle = (ServerResponsePreKeyBundle) incoming; 75 | registrationSendPassword(serverResponsePreKeyBundle); 76 | 77 | } else if (incoming instanceof EncryptedLoginResponseState) { 78 | EncryptedLoginResponseState encryptedLoginResponseState = (EncryptedLoginResponseState) incoming; 79 | returnLoginResults(encryptedLoginResponseState); 80 | 81 | } else if (incoming instanceof LoginResponseState) { 82 | loginResults = new AuthResults("Failed to Login", false); 83 | 84 | } else if (incoming instanceof EncryptedRegistrationResponseState) { 85 | EncryptedRegistrationResponseState encryptedRegistrationResponseState = (EncryptedRegistrationResponseState) incoming; 86 | returnRegistrationResults(encryptedRegistrationResponseState); 87 | 88 | } else if (incoming instanceof EncryptedClientPreKeyBundle) { 89 | EncryptedClientPreKeyBundle encryptedClientPreKeyBundle = (EncryptedClientPreKeyBundle) incoming; 90 | handleRequestedUserPreKeyBundle(encryptedClientPreKeyBundle); 91 | 92 | } else if (incoming instanceof EncryptedMMessageObject) { 93 | EncryptedMMessageObject incomingMessage = (EncryptedMMessageObject) incoming; 94 | handleIncomingMMessage(incomingMessage); 95 | } 96 | } 97 | 98 | } catch (Exception e) { 99 | e.printStackTrace(); 100 | } 101 | } 102 | 103 | private void registrationSendPassword(ServerResponsePreKeyBundle bundle) throws Exception { 104 | while (password.equals("")) { 105 | Thread.sleep(1000); 106 | } 107 | 108 | SignalProtocolAddress serverAddress = new SignalProtocolAddress("SERVER", 0); 109 | 110 | byte[] encryptedPassword = SignalCrypto.encryptStringMessage(password, serverAddress, bundle.getPreKeyBundle()); 111 | 112 | String actualUsername = Main.getActualUsername(username); 113 | 114 | SignalEncryptedPasswordSend passwordSend = new SignalEncryptedPasswordSend(encryptedPassword, actualUsername); 115 | 116 | OutgoingMessageThread.addOutgoingMessage(passwordSend); 117 | 118 | password = ""; 119 | username = ""; 120 | registrationFlag = false; 121 | } 122 | 123 | private void returnLoginResults(EncryptedLoginResponseState encryptedLoginResponseState) throws Exception { 124 | byte[] serializedLoginResponseState = SignalCrypto.decryptMessage(encryptedLoginResponseState.getEncryptedData(), new SignalProtocolAddress("SERVER", 0)); 125 | LoginResponseState state = (LoginResponseState) net.strangled.maladan.cli.Main.reconstructSerializedObject(serializedLoginResponseState); 126 | 127 | if (state.isValidLogin()) { 128 | loginResults = new AuthResults("Logged In Successfully", true); 129 | } else { 130 | loginResults = new AuthResults("Failed to Login.", false); 131 | } 132 | } 133 | 134 | private void returnRegistrationResults(EncryptedRegistrationResponseState encryptedRegistrationResponseState) throws Exception { 135 | byte[] serializedRegistrationResponseState = SignalCrypto.decryptMessage(encryptedRegistrationResponseState.getEncryptedData(), new SignalProtocolAddress("SERVER", 0)); 136 | RegistrationResponseState state = (RegistrationResponseState) net.strangled.maladan.cli.Main.reconstructSerializedObject(serializedRegistrationResponseState); 137 | boolean loginState = state.isValidRegistration(); 138 | 139 | if (loginState) { 140 | loginResults = new AuthResults("Successfully Registered.", true); 141 | } else { 142 | loginResults = new AuthResults("Registration Failed.", false); 143 | } 144 | } 145 | 146 | private void handleRequestedUserPreKeyBundle(EncryptedClientPreKeyBundle bundle) throws Exception { 147 | byte[] serializedResponseBundle = SignalCrypto.decryptMessage(bundle.getEncryptedData(), new SignalProtocolAddress("SERVER", 0)); 148 | ServerResponsePreKeyBundle serverResponsePreKeyBundle = (ServerResponsePreKeyBundle) Main.reconstructSerializedObject(serializedResponseBundle); 149 | 150 | IncomingMessageThread.setUserBundle(serverResponsePreKeyBundle.getPreKeyBundle()); 151 | } 152 | 153 | private void handleIncomingMMessage(EncryptedMMessageObject object) throws Exception { 154 | byte[] serializedMMessageObject = SignalCrypto.decryptMessage(object.getEncryptedMessage(), new SignalProtocolAddress("SERVER", 0)); 155 | MMessageObject messageObject = (MMessageObject) Main.reconstructSerializedObject(serializedMMessageObject); 156 | 157 | incomingMessages.add(messageObject); 158 | } 159 | 160 | public void start() { 161 | if (t == null) { 162 | t = new Thread(this); 163 | t.start(); 164 | } 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/net/MaladaN/Tor/thoughtcrime/MySignalProtocolStore.java: -------------------------------------------------------------------------------- 1 | package net.MaladaN.Tor.thoughtcrime; 2 | 3 | 4 | import org.whispersystems.libsignal.IdentityKey; 5 | import org.whispersystems.libsignal.IdentityKeyPair; 6 | import org.whispersystems.libsignal.SignalProtocolAddress; 7 | import org.whispersystems.libsignal.state.PreKeyRecord; 8 | import org.whispersystems.libsignal.state.SessionRecord; 9 | import org.whispersystems.libsignal.state.SignalProtocolStore; 10 | import org.whispersystems.libsignal.state.SignedPreKeyRecord; 11 | 12 | import java.sql.Connection; 13 | import java.sql.PreparedStatement; 14 | import java.sql.ResultSet; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class MySignalProtocolStore implements SignalProtocolStore { 19 | 20 | @Override 21 | public IdentityKeyPair getIdentityKeyPair() { 22 | Connection conn = GetSQLConnection.getConn(); 23 | IdentityKeyPair keyPair = null; 24 | if (conn != null) { 25 | try { 26 | String sql = "SELECT identityKeyPair FROM localIdentityStorage"; 27 | PreparedStatement ps = conn.prepareStatement(sql); 28 | ResultSet rs = ps.executeQuery(); 29 | rs.next(); 30 | byte[] testKeyPair = rs.getBytes("identityKeyPair"); 31 | keyPair = new IdentityKeyPair(testKeyPair); 32 | conn.close(); 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | return keyPair; 38 | } else { 39 | return null; 40 | } 41 | } 42 | 43 | @Override 44 | public int getLocalRegistrationId() { 45 | Connection conn = GetSQLConnection.getConn(); 46 | int localRegId = 0; 47 | if (conn != null) { 48 | try { 49 | String sql = "SELECT localRegistrationId FROM localIdentityStorage"; 50 | PreparedStatement ps = conn.prepareStatement(sql); 51 | ResultSet rs = ps.executeQuery(); 52 | rs.next(); 53 | localRegId = rs.getInt("localRegistrationId"); 54 | conn.close(); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | return localRegId; 60 | } 61 | 62 | @Override 63 | public boolean saveIdentity(SignalProtocolAddress signalProtocolAddress, IdentityKey identityKey) { 64 | Connection conn = GetSQLConnection.getConn(); 65 | boolean alreadyExists = isTrustedIdentity(signalProtocolAddress, identityKey, Direction.SENDING); 66 | if (conn != null && !alreadyExists) { 67 | try { 68 | String sql = "INSERT INTO identityKeyStorage (signalProtocolAddress, identityKey) VALUES (?, ?)"; 69 | PreparedStatement ps = conn.prepareStatement(sql); 70 | ps.setString(1, signalProtocolAddress.toString()); 71 | ps.setBytes(2, identityKey.serialize()); 72 | ps.execute(); 73 | conn.close(); 74 | return true; 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | return false; 78 | } 79 | } 80 | return false; 81 | } 82 | 83 | @Override 84 | public boolean isTrustedIdentity(SignalProtocolAddress signalProtocolAddress, IdentityKey identityKey, Direction direction) { 85 | Connection conn = GetSQLConnection.getConn(); 86 | boolean isTrusted = false; 87 | if (identityKey != null) { 88 | if (conn != null) { 89 | try { 90 | String sql = "SELECT signalProtocolAddress, identityKey FROM identityKeyStorage WHERE identityKey=?"; 91 | PreparedStatement ps = conn.prepareStatement(sql); 92 | ps.setBytes(1, identityKey.serialize()); 93 | ResultSet rs = ps.executeQuery(); 94 | while (rs.next()) { 95 | if (signalProtocolAddress.toString().equals(rs.getString("signalProtocolAddress"))) { 96 | isTrusted = true; 97 | } 98 | } 99 | conn.close(); 100 | } catch (Exception e) { 101 | e.printStackTrace(); 102 | } 103 | } 104 | } else { 105 | if (conn != null) { 106 | try { 107 | String sql = "SELECT signalProtocolAddress FROM identityKeyStorage WHERE signalProtocolAddress=?"; 108 | PreparedStatement ps = conn.prepareStatement(sql); 109 | ps.setString(1, signalProtocolAddress.toString()); 110 | ResultSet rs = ps.executeQuery(); 111 | boolean exists = rs.next(); 112 | conn.close(); 113 | return exists; 114 | } catch (Exception e) { 115 | e.printStackTrace(); 116 | } 117 | } 118 | } 119 | return isTrusted; 120 | } 121 | 122 | @Override 123 | public PreKeyRecord loadPreKey(int i) { 124 | Connection conn = GetSQLConnection.getConn(); 125 | PreKeyRecord recoveredRecord = null; 126 | if (conn != null) { 127 | try { 128 | String sql = "SELECT preKeyRecord FROM preKeyStorage WHERE keyId =?"; 129 | PreparedStatement ps = conn.prepareStatement(sql); 130 | ps.setInt(1, i); 131 | ResultSet rs = ps.executeQuery(); 132 | rs.next(); 133 | recoveredRecord = new PreKeyRecord(rs.getBytes("preKeyRecord")); 134 | conn.close(); 135 | } catch (Exception e) { 136 | e.printStackTrace(); 137 | } 138 | } 139 | 140 | return recoveredRecord; 141 | } 142 | 143 | @Override 144 | public void storePreKey(int i, PreKeyRecord preKeyRecord) { 145 | Connection conn = GetSQLConnection.getConn(); 146 | if (conn != null) { 147 | try { 148 | String sql = "INSERT INTO preKeyStorage (preKeyRecord, keyId) VALUES (?, ?)"; 149 | PreparedStatement ps = conn.prepareStatement(sql); 150 | ps.setBytes(1, preKeyRecord.serialize()); 151 | ps.setInt(2, i); 152 | ps.execute(); 153 | conn.close(); 154 | } catch (Exception e) { 155 | e.printStackTrace(); 156 | } 157 | } 158 | } 159 | 160 | @Override 161 | public boolean containsPreKey(int i) { 162 | boolean exists = false; 163 | try { 164 | if (loadPreKey(i) != null) { 165 | exists = true; 166 | } 167 | } catch (Exception e) { 168 | e.printStackTrace(); 169 | } 170 | 171 | return exists; 172 | } 173 | 174 | @Override 175 | public void removePreKey(int i) { 176 | Connection conn = GetSQLConnection.getConn(); 177 | if (conn != null) { 178 | try { 179 | String sql = "DELETE FROM preKeyStorage WHERE keyId=?"; 180 | PreparedStatement ps = conn.prepareStatement(sql); 181 | ps.setInt(1, i); 182 | ps.execute(); 183 | conn.close(); 184 | } catch (Exception e) { 185 | e.printStackTrace(); 186 | } 187 | } 188 | } 189 | 190 | @Override 191 | public SessionRecord loadSession(SignalProtocolAddress signalProtocolAddress) { 192 | Connection conn = GetSQLConnection.getConn(); 193 | SessionRecord sr = null; 194 | if (conn != null) { 195 | try { 196 | String sql = "SELECT sessionRecord FROM sessionStoreStorage WHERE protocolAddress=?"; 197 | PreparedStatement ps = conn.prepareStatement(sql); 198 | ps.setString(1, signalProtocolAddress.toString()); 199 | ResultSet rs = ps.executeQuery(); 200 | if (rs.next()) { 201 | sr = new SessionRecord(rs.getBytes("sessionRecord")); 202 | } 203 | conn.close(); 204 | } catch (Exception e) { 205 | e.printStackTrace(); 206 | } 207 | } 208 | if (sr != null) { 209 | return sr; 210 | } else { 211 | return new SessionRecord(); 212 | } 213 | } 214 | 215 | @Override 216 | public List getSubDeviceSessions(String s) { 217 | Connection conn = GetSQLConnection.getConn(); 218 | List retrievedIds = new ArrayList<>(); 219 | if (conn != null) { 220 | try { 221 | String sql = "SELECT * FROM sessionStoreStorage"; 222 | PreparedStatement ps = conn.prepareStatement(sql); 223 | ResultSet rs = ps.executeQuery(); 224 | while (rs.next()) { 225 | String protoToString = rs.getString("protocolAddress"); 226 | if (protoToString.contains(s)) { 227 | StringBuilder tempInteger = new StringBuilder(); 228 | boolean passedColon = false; 229 | for (char c : protoToString.toCharArray()) { 230 | if (Character.isDigit(c) && passedColon) { 231 | tempInteger.append(c); 232 | } 233 | if (c == ':') { 234 | passedColon = true; 235 | } 236 | } 237 | if (!tempInteger.toString().equals("")) { 238 | retrievedIds.add(Integer.valueOf(tempInteger.toString())); 239 | } 240 | } 241 | } 242 | conn.close(); 243 | } catch (Exception e) { 244 | e.printStackTrace(); 245 | } 246 | } 247 | if (retrievedIds.isEmpty()) { 248 | return null; 249 | } else { 250 | return retrievedIds; 251 | } 252 | } 253 | 254 | @Override 255 | public void storeSession(SignalProtocolAddress signalProtocolAddress, SessionRecord sessionRecord) { 256 | Connection conn = GetSQLConnection.getConn(); 257 | if (conn != null) { 258 | if (!containsSession(signalProtocolAddress)) { 259 | try { 260 | String sql = "INSERT INTO sessionStoreStorage (protocolAddress, sessionRecord) VALUES (?, ?)"; 261 | PreparedStatement ps = conn.prepareStatement(sql); 262 | ps.setString(1, signalProtocolAddress.toString()); 263 | ps.setBytes(2, sessionRecord.serialize()); 264 | ps.execute(); 265 | conn.close(); 266 | } catch (Exception e) { 267 | e.printStackTrace(); 268 | } 269 | } else { 270 | try { 271 | String sql = "UPDATE sessionStoreStorage SET sessionRecord = ? WHERE protocolAddress = ?"; 272 | PreparedStatement ps = conn.prepareStatement(sql); 273 | ps.setBytes(1, sessionRecord.serialize()); 274 | ps.setString(2, signalProtocolAddress.toString()); 275 | ps.execute(); 276 | conn.close(); 277 | } catch (Exception e) { 278 | e.printStackTrace(); 279 | } 280 | 281 | } 282 | } 283 | } 284 | 285 | @Override 286 | public boolean containsSession(SignalProtocolAddress signalProtocolAddress) { 287 | Connection conn = GetSQLConnection.getConn(); 288 | if (conn != null) { 289 | try { 290 | String sql = "SELECT sessionRecord FROM sessionStoreStorage WHERE protocolAddress=?"; 291 | PreparedStatement ps = conn.prepareStatement(sql); 292 | ps.setString(1, signalProtocolAddress.toString()); 293 | ResultSet rs = ps.executeQuery(); 294 | boolean valid = rs.next(); 295 | conn.close(); 296 | return valid; 297 | } catch (Exception e) { 298 | e.printStackTrace(); 299 | return false; 300 | } 301 | } else { 302 | return false; 303 | } 304 | } 305 | 306 | @Override 307 | public void deleteSession(SignalProtocolAddress signalProtocolAddress) { 308 | Connection conn = GetSQLConnection.getConn(); 309 | if (conn != null) { 310 | try { 311 | String sql = "DELETE FROM sessionStoreStorage WHERE protocolAddress=?"; 312 | PreparedStatement ps = conn.prepareStatement(sql); 313 | ps.setString(1, signalProtocolAddress.toString()); 314 | ps.execute(); 315 | conn.close(); 316 | } catch (Exception e) { 317 | e.printStackTrace(); 318 | } 319 | } 320 | } 321 | 322 | @Override 323 | public void deleteAllSessions(String s) { 324 | Connection conn = GetSQLConnection.getConn(); 325 | if (conn != null) { 326 | try { 327 | String sql = "DELETE FROM sessionStoreStorage WHERE protocolAddress like ?"; 328 | PreparedStatement ps = conn.prepareStatement(sql); 329 | ps.setString(1, ('%' + s + '%')); 330 | ps.execute(); 331 | conn.close(); 332 | } catch (Exception e) { 333 | e.printStackTrace(); 334 | } 335 | } 336 | } 337 | 338 | @Override 339 | public SignedPreKeyRecord loadSignedPreKey(int i) { 340 | Connection conn = GetSQLConnection.getConn(); 341 | SignedPreKeyRecord pkr = null; 342 | if (conn != null) { 343 | try { 344 | String sql = "SELECT signedPreKeyRecord FROM signedPreKeyStore WHERE keyId = ?"; 345 | PreparedStatement ps = conn.prepareStatement(sql); 346 | ps.setInt(1, i); 347 | ResultSet rs = ps.executeQuery(); 348 | rs.next(); 349 | pkr = new SignedPreKeyRecord(rs.getBytes("signedPreKeyRecord")); 350 | conn.close(); 351 | } catch (Exception e) { 352 | e.printStackTrace(); 353 | } 354 | } 355 | return pkr; 356 | } 357 | 358 | @Override 359 | public List loadSignedPreKeys() { 360 | Connection conn = GetSQLConnection.getConn(); 361 | List pkr = new ArrayList<>(); 362 | if (conn != null) { 363 | try { 364 | String sql = "SELECT signedPreKeyRecord FROM signedPreKeyStore"; 365 | PreparedStatement ps = conn.prepareStatement(sql); 366 | ResultSet rs = ps.executeQuery(); 367 | while (rs.next()) { 368 | pkr.add(new SignedPreKeyRecord(rs.getBytes("signedPreKeyRecord"))); 369 | } 370 | conn.close(); 371 | } catch (Exception e) { 372 | e.printStackTrace(); 373 | } 374 | } 375 | if (pkr.isEmpty()) { 376 | return null; 377 | } else { 378 | return pkr; 379 | } 380 | } 381 | 382 | @Override 383 | public void storeSignedPreKey(int i, SignedPreKeyRecord signedPreKeyRecord) { 384 | Connection conn = GetSQLConnection.getConn(); 385 | if (conn != null) { 386 | try { 387 | String sql = "INSERT INTO signedPreKeyStore (signedPreKeyRecord, keyId) VALUES (?, ?)"; 388 | PreparedStatement ps = conn.prepareStatement(sql); 389 | ps.setBytes(1, signedPreKeyRecord.serialize()); 390 | ps.setInt(2, i); 391 | ps.execute(); 392 | conn.close(); 393 | } catch (Exception e) { 394 | e.printStackTrace(); 395 | } 396 | } 397 | } 398 | 399 | @Override 400 | public boolean containsSignedPreKey(int i) { 401 | Connection conn = GetSQLConnection.getConn(); 402 | if (conn != null) { 403 | try { 404 | String sql = "SELECT signedPreKeyRecord FROM signedPreKeyStore WHERE keyId = ?"; 405 | PreparedStatement ps = conn.prepareStatement(sql); 406 | ps.setInt(1, i); 407 | ResultSet rs = ps.executeQuery(); 408 | boolean contains = rs.next(); 409 | conn.close(); 410 | return contains; 411 | } catch (Exception e) { 412 | e.printStackTrace(); 413 | return false; 414 | } 415 | } else { 416 | return false; 417 | } 418 | } 419 | 420 | @Override 421 | public void removeSignedPreKey(int i) { 422 | Connection conn = GetSQLConnection.getConn(); 423 | if (conn != null) { 424 | try { 425 | String sql = "DELETE FROM signedPreKeyStorage WHERE keyId = ?"; 426 | PreparedStatement ps = conn.prepareStatement(sql); 427 | ps.setInt(1, i); 428 | ps.execute(); 429 | conn.close(); 430 | } catch (Exception e) { 431 | e.printStackTrace(); 432 | } 433 | } 434 | } 435 | } 436 | -------------------------------------------------------------------------------- /src/net/strangled/maladan/cli/Main.java: -------------------------------------------------------------------------------- 1 | package net.strangled.maladan.cli; 2 | 3 | 4 | import net.MaladaN.Tor.thoughtcrime.InitData; 5 | import net.MaladaN.Tor.thoughtcrime.MySignalProtocolStore; 6 | import net.MaladaN.Tor.thoughtcrime.SignalCrypto; 7 | import net.i2p.client.streaming.I2PSocket; 8 | import net.i2p.client.streaming.I2PSocketManager; 9 | import net.i2p.client.streaming.I2PSocketManagerFactory; 10 | import net.i2p.data.Destination; 11 | import net.strangled.maladan.serializables.Authentication.*; 12 | import net.strangled.maladan.serializables.Messaging.*; 13 | import net.strangled.maladan.shared.AuthResults; 14 | import net.strangled.maladan.shared.IncomingMessageThread; 15 | import net.strangled.maladan.shared.LocalLoginDataStore; 16 | import net.strangled.maladan.shared.OutgoingMessageThread; 17 | import org.whispersystems.libsignal.IdentityKey; 18 | import org.whispersystems.libsignal.SignalProtocolAddress; 19 | import org.whispersystems.libsignal.state.PreKeyBundle; 20 | 21 | import java.io.*; 22 | import java.security.MessageDigest; 23 | import java.security.NoSuchAlgorithmException; 24 | import java.util.Base64; 25 | import java.util.Scanner; 26 | import java.util.UUID; 27 | 28 | public class Main { 29 | private static boolean running = true; 30 | 31 | public static void main(String[] args) { 32 | Scanner input = new Scanner(System.in); 33 | String host; 34 | int port; 35 | 36 | System.out.println("Enter the host and port of the configured i2p router. If you are running the i2p router on this machine, these can be left blank."); 37 | System.out.print("Host: "); 38 | host = input.nextLine(); 39 | System.out.print("Port: "); 40 | port = input.nextInt(); 41 | input.nextLine(); 42 | connect(host, port); 43 | System.out.println("Connected."); 44 | 45 | MessageHandlerThread messageHandlerThread = new MessageHandlerThread(); 46 | messageHandlerThread.start(); 47 | 48 | System.out.println("Enter an option: register or login"); 49 | String received = input.nextLine(); 50 | received = received.toLowerCase(); 51 | 52 | if (received.equals("register")) { 53 | System.out.println("Enter your username: "); 54 | String username = input.nextLine(); 55 | username = username.toLowerCase(); 56 | System.out.println("Enter your password: "); 57 | String password = input.nextLine(); 58 | 59 | try { 60 | AuthResults results = register(username, password, "tester123"); 61 | 62 | if (results != null) { 63 | System.out.println(results.getFormattedResults()); 64 | } 65 | 66 | } catch (Exception e) { 67 | e.printStackTrace(); 68 | } 69 | } else { 70 | System.out.println("Enter your password: "); 71 | String password = input.nextLine(); 72 | 73 | try { 74 | AuthResults results = login(password); 75 | 76 | if (results != null) { 77 | System.out.println(results.getFormattedResults()); 78 | } 79 | 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | } 83 | } 84 | try { 85 | System.out.println("Enter the username of the user you would like to converse with: "); 86 | String username = input.nextLine(); 87 | 88 | System.out.println("Enter a filename to test file encryption."); 89 | String filename = input.nextLine(); 90 | boolean successful = sendFileMessage(filename, username); 91 | 92 | if (successful) { 93 | System.out.println("Successfully encrypted and saved."); 94 | } else { 95 | System.out.println("Something went wrong."); 96 | } 97 | 98 | while (running) { 99 | System.out.println("Enter a message to send: "); 100 | String messageToSend = input.nextLine(); 101 | boolean sent = sendStringMessage(messageToSend, username); 102 | if (sent) { 103 | System.out.println("Message Sent"); 104 | } else { 105 | System.out.println("Message failed to send"); 106 | } 107 | } 108 | } catch (Exception e) { 109 | e.printStackTrace(); 110 | } 111 | 112 | } 113 | 114 | //hash strings and return bytes using the SHA-256 digest 115 | public static byte[] hashData(String data) throws NoSuchAlgorithmException { 116 | MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); 117 | messageDigest.update(data.getBytes()); 118 | return messageDigest.digest(); 119 | } 120 | 121 | public static byte[] serializeObject(Object object) throws IOException { 122 | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { 123 | ObjectOutput out = new ObjectOutputStream(bos); 124 | out.writeObject(object); 125 | out.flush(); 126 | return bos.toByteArray(); 127 | } 128 | } 129 | 130 | public static Object reconstructSerializedObject(byte[] object) throws Exception { 131 | try (ByteArrayInputStream bis = new ByteArrayInputStream(object)) { 132 | ObjectInput in = new ObjectInputStream(bis); 133 | return in.readObject(); 134 | } 135 | } 136 | 137 | //takes string username passed in by the user and turns it into user's actual 138 | //base64 representation of their byte username. 139 | public static String getActualUsername(String originalUsername) throws Exception { 140 | byte[] hashedUsername = hashData(originalUsername); 141 | Base64.Encoder encoder = Base64.getEncoder(); 142 | return encoder.encodeToString(hashedUsername); 143 | } 144 | 145 | //takes the base64 username of a possible message recipient and checks if we have 146 | //a valid signal messaging session. If not we request a pre key bundle for the 147 | //recipient user from the server. If a session already exists the method returns null. 148 | 149 | //when the SignalCrypto library receives a prekey bundle of null it assumes that a session 150 | //exists in our database and attempts to encrypt using that session. 151 | private static PreKeyBundle getPreKeyBundleIfNoSession(String base64Username) throws Exception { 152 | boolean sessionExists = new MySignalProtocolStore().containsSession(new SignalProtocolAddress(base64Username, 0)); 153 | PreKeyBundle requestedUserBundle = null; 154 | 155 | if (!sessionExists) { 156 | User sendUser = new User(false, base64Username); 157 | byte[] serializedUser = serializeObject(sendUser); 158 | byte[] encryptedSerializedUser = SignalCrypto.encryptByteMessage(serializedUser, new SignalProtocolAddress("SERVER", 0), null); 159 | 160 | IEncryptedAuth encryptedUser = new EncryptedUser(); 161 | encryptedUser.storeEncryptedData(encryptedSerializedUser); 162 | 163 | OutgoingMessageThread.addOutgoingMessage(encryptedUser); 164 | 165 | while (IncomingMessageThread.getUserBundle() == null) { 166 | Thread.sleep(600); 167 | } 168 | 169 | requestedUserBundle = IncomingMessageThread.getUserBundle(); 170 | IncomingMessageThread.setUserBundle(null); 171 | } 172 | return requestedUserBundle; 173 | } 174 | 175 | static I2PSocket connect(String host, int port) { 176 | I2PSocket sock; 177 | I2PSocketManager manager; 178 | try { 179 | 180 | if (!(host.equals("")) && port != 0) { 181 | manager = I2PSocketManagerFactory.createManager(host, port); 182 | } else { 183 | manager = I2PSocketManagerFactory.createManager(); 184 | } 185 | 186 | Destination destination = new Destination("JaiCQHfweWn8Acp1XyTse1GL1392f-ZKzal9kyOhBAo-oYtnXAJIe8JU73taAjROnWApCe-hRUOlb6RkwW3kL2orqR8zhO6RDQMmOMy7FYqCq3UlNOOEQbLO1wo3kd65PA8D1zkhdFYqfYsQk4uEgci4~bamadKNOJXE1C~A53kEY-kYQ-vRSdV9LSFCRGay5BNDVJ1lFI~CYJRmreMx1hvd9YAsUg0fuy-U0AzylXwigSRejBhCNfsF-6-dLCQa8KYg8gzxe0DHUNRw18Yf1VwnvV7X2gM0CRQVcMhu7YgD3iwfT~DKFjZqRbNse~xEF0RtMCfhg7LgyCBRlJGVTj2PeXgxVtWHm3L-BtZ4bB5Ugb6K3ZdUFq9zP~VyKUmUJXSpApqhGdiGUWjj91-OZDJYnh6xgT17i-g0T2tEYLoSx9em~YZQQ~-mO3iSpiccSvmPjOpg9X1XVp9QvIyvWQIwrkv6y6ZgHeTrsxsG8HBZhPbMy6flinJRsCcPnIOlAAAA"); 187 | sock = manager.connect(destination); 188 | 189 | System.out.println("Creating Threads..."); 190 | new OutgoingMessageThread(sock.getOutputStream()).start(); 191 | new IncomingMessageThread(sock.getInputStream()).start(); 192 | System.out.println("Threads Created."); 193 | 194 | } catch (Exception e) { 195 | e.printStackTrace(); 196 | return null; 197 | } 198 | return sock; 199 | } 200 | 201 | static AuthResults login(String password) throws Exception { 202 | if (password.isEmpty()) { 203 | return null; 204 | } 205 | 206 | SignalProtocolAddress address = new SignalProtocolAddress("SERVER", 0); 207 | 208 | User user = LocalLoginDataStore.getData(); 209 | 210 | //public key retrieved to verify that the server has the same one stored. 211 | //if the user changes their key data they won't be able to login. 212 | IdentityKey key = new MySignalProtocolStore().getIdentityKeyPair().getPublicKey(); 213 | 214 | byte[] serializedKey = key.serialize(); 215 | 216 | if (user != null) { 217 | String username = user.getUsername(); 218 | 219 | byte[] encryptedPassword = SignalCrypto.encryptStringMessage(password, address, null); 220 | 221 | ServerLogin login = new ServerLogin(username, encryptedPassword, serializedKey); 222 | 223 | OutgoingMessageThread.addOutgoingMessage(login); 224 | 225 | return waitForAuthData(); 226 | 227 | } else { 228 | return null; 229 | } 230 | } 231 | 232 | static AuthResults register(String username, String password, String uniqueId) throws Exception { 233 | if (username.isEmpty() || password.isEmpty() || uniqueId.isEmpty()) { 234 | return null; 235 | } 236 | 237 | InitData data = SignalCrypto.initStore(); 238 | 239 | String actualUsername = getActualUsername(username); 240 | ServerInit init = new ServerInit(actualUsername, uniqueId, data); 241 | 242 | IncomingMessageThread.setCredentials(password, username); 243 | OutgoingMessageThread.addOutgoingMessage(init); 244 | 245 | LocalLoginDataStore.saveLocaluser(new User(true, actualUsername)); 246 | 247 | return waitForAuthData(); 248 | } 249 | 250 | //used by the login and register method to wait for a response 251 | //from the server. 252 | private static AuthResults waitForAuthData() throws Exception { 253 | while (IncomingMessageThread.getAuthResults() == null) { 254 | Thread.sleep(1000); 255 | } 256 | 257 | AuthResults results = IncomingMessageThread.getAuthResults(); 258 | IncomingMessageThread.clearAuthResults(); 259 | 260 | return results; 261 | } 262 | 263 | static boolean sendStringMessage(String message, String recipientUsername) throws Exception { 264 | String actualRecipientUsername = getActualUsername(recipientUsername); 265 | PreKeyBundle requestedUserBundle = getPreKeyBundleIfNoSession(actualRecipientUsername); 266 | 267 | byte[] eteeMessage = SignalCrypto.encryptStringMessage(message, new SignalProtocolAddress(actualRecipientUsername, 0), requestedUserBundle); 268 | 269 | if (eteeMessage != null) { 270 | User user = LocalLoginDataStore.getData(); 271 | 272 | if (user != null) { 273 | String ourUsername = user.getUsername(); 274 | MMessageObject mMessageObject = new MMessageObject(eteeMessage, actualRecipientUsername, ourUsername); 275 | 276 | byte[] serializedMMessageObject = Main.serializeObject(mMessageObject); 277 | byte[] encryptedSerializedMessageObject = SignalCrypto.encryptByteMessage(serializedMMessageObject, new SignalProtocolAddress("SERVER", 0), null); 278 | 279 | IEncryptedMessage encryptedMMessageObject = new EncryptedMMessageObject(); 280 | encryptedMMessageObject.storeEncryptedMessage(encryptedSerializedMessageObject); 281 | 282 | OutgoingMessageThread.addOutgoingMessage(encryptedMMessageObject); 283 | return true; 284 | } 285 | return false; 286 | 287 | } 288 | return false; 289 | } 290 | 291 | static boolean sendFileMessage(String fileName, String recipientUsername) throws Exception { 292 | 293 | String actualRecipientUsername = getActualUsername(recipientUsername); 294 | String encryptedFilePath = encryptFile(fileName, actualRecipientUsername); 295 | 296 | try (InputStream in = new FileInputStream(encryptedFilePath)) { 297 | User user = LocalLoginDataStore.getData(); 298 | 299 | if (user != null) { 300 | String ourUsername = user.getUsername(); 301 | 302 | File temporaryFile = new File(encryptedFilePath); 303 | byte[] buffer = new byte[FileConstants.bufferLength]; 304 | 305 | 306 | //handles the fact that the file will likely not exactly fit into the buffer sizes. 307 | //If the result of attempting to divide the length of the file by the buffer returns 308 | //a floating point value, the number of buffers is increased by one. 309 | 310 | float numberOfFileObjectsTemp = (float) temporaryFile.length() / (float) FileConstants.bufferLength; 311 | float subtractionValue = numberOfFileObjectsTemp % 1; 312 | boolean needToClean = !(subtractionValue == 0); 313 | 314 | 315 | if (needToClean) { 316 | numberOfFileObjectsTemp -= subtractionValue; 317 | numberOfFileObjectsTemp++; 318 | } 319 | 320 | int numberOfFileObjects = (int) numberOfFileObjectsTemp; 321 | System.out.println("number of objects to send: " + numberOfFileObjects); 322 | 323 | int numberOfFileObjectsIncrementer = numberOfFileObjects - 1; 324 | 325 | int i = 0; 326 | SignalProtocolAddress serverAddress = new SignalProtocolAddress("SERVER", 0); 327 | 328 | while (in.read(buffer) > 0) { 329 | if (i == 0) { 330 | FileInitiation fileStart = new FileInitiation(temporaryFile.length(), ourUsername, actualRecipientUsername, buffer); 331 | 332 | byte[] serializedEncryptedFileStart = SignalCrypto.encryptByteMessage(Main.serializeObject(fileStart), serverAddress, null); 333 | IEncryptedMessage eFI = new EncryptedFileInitiation(); 334 | eFI.storeEncryptedMessage(serializedEncryptedFileStart); 335 | 336 | OutgoingMessageThread.addOutgoingMessage(eFI); 337 | System.out.println("Added Encrypted File Initiation" + i + " to outThread."); 338 | 339 | } else if (i == numberOfFileObjectsIncrementer) { 340 | FileEnd fileEnd = new FileEnd(ourUsername, buffer); 341 | 342 | byte[] serializedEncryptedFileEnd = SignalCrypto.encryptByteMessage(Main.serializeObject(fileEnd), serverAddress, null); 343 | 344 | IEncryptedMessage eFE = new EncryptedFileEnd(); 345 | eFE.storeEncryptedMessage(serializedEncryptedFileEnd); 346 | 347 | OutgoingMessageThread.addOutgoingMessage(eFE); 348 | System.out.println("Added Encrypted File End" + i + " to outThread."); 349 | 350 | } else { 351 | FileSpan fileSpan = new FileSpan(ourUsername, buffer); 352 | 353 | byte[] serializedEncryptedFileSpan = SignalCrypto.encryptByteMessage(Main.serializeObject(fileSpan), serverAddress, null); 354 | 355 | EncryptedFileSpan eFS = new EncryptedFileSpan(); 356 | eFS.storeEncryptedMessage(serializedEncryptedFileSpan); 357 | 358 | OutgoingMessageThread.addOutgoingMessage(eFS); 359 | System.out.println("Added Encrypted File Span" + i + " to outThread."); 360 | } 361 | i++; 362 | } 363 | 364 | } else { 365 | throw new Exception("Local user object is null."); 366 | } 367 | } 368 | 369 | File tempFile = new File(encryptedFilePath); 370 | tempFile.delete(); 371 | 372 | return true; 373 | } 374 | 375 | //returns file path to new encrypted file. 376 | private static String encryptFile(String filePath, String actualRecipientUsername) throws Exception { 377 | File tempFile = new File("Files"); 378 | if (!tempFile.exists()) { 379 | tempFile.mkdir(); 380 | } 381 | 382 | final String temporaryFileDirectory = "Files" + File.separator; 383 | final String uuid = UUID.randomUUID().toString(); 384 | 385 | PreKeyBundle bundle = getPreKeyBundleIfNoSession(actualRecipientUsername); 386 | 387 | File fileToSend = new File(filePath); 388 | String temporaryFilename = temporaryFileDirectory + uuid + fileToSend.getName() + ".mal"; 389 | 390 | try (InputStream in = new FileInputStream(fileToSend); 391 | OutputStream out = new FileOutputStream(temporaryFilename, true)) { 392 | 393 | byte[] buffer = new byte[FileConstants.encryptionBufferLength]; 394 | 395 | //read in buffer of file, encrypt buffer, and write buffer to disk in new encrypted file. 396 | 397 | while ((in.read(buffer)) > 0) { 398 | byte[] encryptedBuffer = SignalCrypto.encryptByteMessage(buffer, new SignalProtocolAddress(actualRecipientUsername, 0), bundle); 399 | 400 | if (encryptedBuffer != null) { 401 | out.write(encryptedBuffer); 402 | 403 | } else { 404 | throw new Exception(); 405 | } 406 | } 407 | out.flush(); 408 | } 409 | return temporaryFilename; 410 | } 411 | } 412 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------