189 lines
9.0 KiB
Java
189 lines
9.0 KiB
Java
package com.jamesquinley.Asecure;
|
|
|
|
import javax.jws.soap.SOAPBinding;
|
|
import javax.mail.*;
|
|
import javax.mail.internet.InternetAddress;
|
|
import javax.mail.internet.MimeMessage;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Properties;
|
|
|
|
public class electronicMailHandler {
|
|
/*
|
|
This will handle both account creation verify and login verify tasks, it will not verify for token based logins as
|
|
that form of login is client controlled and no user input is allowed, hacked clients are also locked out of the network
|
|
*/
|
|
static final String senderEmailId = "obsidiancorestudios@gmail.com";
|
|
static final String senderPassword = "dcixokaivbyxbmnj";
|
|
static final String emailSMTPserver = "smtp.gmail.com";
|
|
static final String emailSMTPPort = "465";
|
|
public static void Onboarding(String receiverEmail, String User) {
|
|
//get date for email
|
|
Date date = new Date();
|
|
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
|
|
String Date = formatter.format(date);
|
|
//get time for sign in time
|
|
Date dt = new Date();
|
|
SimpleDateFormat dateFormat;
|
|
dateFormat = new SimpleDateFormat("kk:mm:ss");
|
|
|
|
Properties props = new Properties();
|
|
props.put("mail.smtp.host", emailSMTPserver);
|
|
props.put("mail.smtp.socketFactory.port", emailSMTPPort);
|
|
props.put("mail.smtp.socketFactory.class",
|
|
"javax.net.ssl.SSLSocketFactory");
|
|
props.put("mail.smtp.auth", "true");
|
|
props.put("mail.smtp.port", emailSMTPPort);
|
|
|
|
try {
|
|
Authenticator auth = new SMTPAuthenticator();
|
|
Session session = Session.getInstance(props, auth);
|
|
Message message = new MimeMessage(session);
|
|
message.setFrom(new InternetAddress(senderEmailId));
|
|
message.setRecipients(Message.RecipientType.TO,
|
|
InternetAddress.parse(receiverEmail));
|
|
message.setSubject("Welcome To Obsidian Core Studios!");
|
|
message.setText("Seems you've signed up for an account we're happy you're here, and welcome to the Obsidian Core Studios Family! \n\n" +
|
|
"This Was Sent On Behalf Of Obsidian Core Studios By Our Super Cool Login Robots." +
|
|
"\nYou'll Only Get This Email Once." +
|
|
"\nThis Account Was Created For: " + User);
|
|
|
|
Transport.send(message);
|
|
System.out.println("Sent Onboarding Email");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
System.err.println("Email ONBOARD Not sent due to an error");
|
|
if (e instanceof SendFailedException) {
|
|
secureCalls.banAction(receiverEmail);
|
|
}
|
|
}
|
|
}
|
|
public static void newLocation (String receiverEmail, String User, String Adr, String OldAdr) {
|
|
//get date for email
|
|
Date date = new Date();
|
|
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
|
|
String Date = formatter.format(date);
|
|
//get time for sign in time
|
|
Date dt = new Date();
|
|
SimpleDateFormat dateFormat;
|
|
dateFormat = new SimpleDateFormat("kk:mm:ss");
|
|
|
|
Properties props = new Properties();
|
|
props.put("mail.smtp.host", emailSMTPserver);
|
|
props.put("mail.smtp.socketFactory.port", emailSMTPPort);
|
|
props.put("mail.smtp.socketFactory.class",
|
|
"javax.net.ssl.SSLSocketFactory");
|
|
props.put("mail.smtp.auth", "true");
|
|
props.put("mail.smtp.port", emailSMTPPort);
|
|
|
|
try {
|
|
Authenticator auth = new SMTPAuthenticator();
|
|
Session session = Session.getInstance(props, auth);
|
|
Message message = new MimeMessage(session);
|
|
message.setFrom(new InternetAddress(senderEmailId));
|
|
message.setRecipients(Message.RecipientType.TO,
|
|
InternetAddress.parse(receiverEmail));
|
|
message.setSubject("Obsidian Core Account Login Notice | " + Date);
|
|
message.setText("Something seems fishy, a login was detected at a new location " + Adr +" "+ "(at " + dateFormat.format(dt) + " PST)" + ".\nIf this was you ignore this email, if it wasn't you, please contact us (Respond to this email).\n\n\n\n" +
|
|
"\nThis email (" + receiverEmail + ") is linked to the Obsidian Core account: "+ User + " \nThese security emails can't be opted out of.\n\nThis was sent on behalf of Obsidian Core Studios by our super cool login robots.\n\n\n\n" +
|
|
"The MAC address used has been set as your account's default, as well as past logins ("+Adr + ")");
|
|
|
|
Transport.send(message);
|
|
System.out.println("Alert Sent");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
System.err.println("Was Not Sent Because Of An Error.");
|
|
}
|
|
}
|
|
|
|
public static void otkEmail (String receiverEmail, String Key, String User) {
|
|
//get date for email
|
|
Date date = new Date();
|
|
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
|
|
String Date = formatter.format(date);
|
|
//get time for sign in time
|
|
Date dt = new Date();
|
|
SimpleDateFormat dateFormat;
|
|
dateFormat = new SimpleDateFormat("kk:mm:ss");
|
|
|
|
Properties props = new Properties();
|
|
props.put("mail.smtp.host", emailSMTPserver);
|
|
props.put("mail.smtp.socketFactory.port", emailSMTPPort);
|
|
props.put("mail.smtp.socketFactory.class",
|
|
"javax.net.ssl.SSLSocketFactory");
|
|
props.put("mail.smtp.auth", "true");
|
|
props.put("mail.smtp.port", emailSMTPPort);
|
|
|
|
try {
|
|
Authenticator auth = new SMTPAuthenticator();
|
|
Session session = Session.getInstance(props, auth);
|
|
Message message = new MimeMessage(session);
|
|
message.setFrom(new InternetAddress(senderEmailId));
|
|
message.setRecipients(Message.RecipientType.TO,
|
|
InternetAddress.parse(receiverEmail));
|
|
message.setSubject("Obsidian Core Account Notice");
|
|
message.setText("Hey there, as you may have seen in the launcher, you need a one time key to continue, this email can help! " +
|
|
"\nBefore we give you the required key to continue, a gentle reminder to NEVER SHARE YOUR PASSWORD OR ONE TIME KEY! " +
|
|
"\nWell, good luck! Your one time key is: " + Key +
|
|
"\nThis key will remain active until used, it was generated at your login attempt, and won't be regenerated after the initial creation of said key." +
|
|
"\nThis key will only work with the account tied to the username: " + User + ", and will only work one time, its in the name.");
|
|
|
|
Transport.send(message);
|
|
System.out.println("Alert Sent");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
System.err.println("Was Not Sent Because Of An Error.");
|
|
}
|
|
|
|
}
|
|
public static void otkMigrate (String receiverEmail, String User) {
|
|
//get date for email
|
|
Date date = new Date();
|
|
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
|
|
String Date = formatter.format(date);
|
|
//get time for sign in time
|
|
Date dt = new Date();
|
|
SimpleDateFormat dateFormat;
|
|
dateFormat = new SimpleDateFormat("kk:mm:ss");
|
|
|
|
Properties props = new Properties();
|
|
props.put("mail.smtp.host", emailSMTPserver);
|
|
props.put("mail.smtp.socketFactory.port", emailSMTPPort);
|
|
props.put("mail.smtp.socketFactory.class",
|
|
"javax.net.ssl.SSLSocketFactory");
|
|
props.put("mail.smtp.auth", "true");
|
|
props.put("mail.smtp.port", emailSMTPPort);
|
|
|
|
try {
|
|
Authenticator auth = new SMTPAuthenticator();
|
|
Session session = Session.getInstance(props, auth);
|
|
Message message = new MimeMessage(session);
|
|
message.setFrom(new InternetAddress(senderEmailId));
|
|
message.setRecipients(Message.RecipientType.TO,
|
|
InternetAddress.parse(receiverEmail));
|
|
message.setSubject("Obsidian Core Account Notice");
|
|
message.setText("The migration process has been completed, and the key is no longer valid.\n" +
|
|
"You will not receive a migration popup on login unless the account service changes hashes again.\n" +
|
|
"Welcome back to your account, and have a great day!\n" +
|
|
"\n\n\n\n\n" +
|
|
"This email is automated, sent to the owner of the account (" + User + ")." + " Please don't reply to this email.");
|
|
|
|
Transport.send(message);
|
|
System.out.println("Alert Sent");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
System.err.println("Was Not Sent Because Of An Error.");
|
|
}
|
|
|
|
}
|
|
private static class SMTPAuthenticator extends
|
|
javax.mail.Authenticator {
|
|
public PasswordAuthentication
|
|
getPasswordAuthentication() {
|
|
return new PasswordAuthentication(senderEmailId,
|
|
senderPassword);
|
|
}
|
|
}
|
|
|
|
}
|