More Intel AMT ACM improvements.

Ylian Saint-Hilaire committed Jun 20, 2019 at 16:56 UTC 56637d4d58f2ed9dba6dd600389d7a368f7d6925
6 files changed +29 -39
agents/meshcore.js
+3 -3
@@ -754,7 +754,7 @@ function createMeshCore(agent)
754 // Store the latest Intel AMT policy
755 amtPolicy = data.amtPolicy;
756 if (data.amtPolicy != null) { db.Put('amtPolicy', JSON.stringify(data.amtPolicy)); } else { db.Put('amtPolicy', null); }
757 - if (amt != null) { amt.setPolicy(amtPolicy); }
757 + if (amt != null) { amt.setPolicy(amtPolicy, true); }
758 break;
759 }
760 case 'getScript': {
@@ -1533,7 +1533,7 @@ function createMeshCore(agent)
1533 var response = null;
1534 switch (cmd) {
1535 case 'help': { // Displays available commands
1536 - response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm, amtdeactivate,\r\namtpolicy, getscript, getclip, setclip.';
1536 + response = 'Available commands: help, info, osinfo, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm,\r\namtdeactivate, amtpolicy, getscript, getclip, setclip.';
1537 break;
1538 }
1539 /*
@@ -2067,7 +2067,7 @@ function createMeshCore(agent)
2067 if (typeof text == 'object') { text = JSON.stringify(text); }
2068 mesh.SendCommand({ "action": "msg", "type": "console", "value": text, "sessionid": sessionid });
2069 }
2070 -
2070 +
2071 // Called before the process exits
2072 //process.exit = function (code) { console.log("Exit with code: " + code.toString()); }
2073
agents/meshcore.min.js
+3 -3
@@ -754,7 +754,7 @@ function createMeshCore(agent)
754 // Store the latest Intel AMT policy
755 amtPolicy = data.amtPolicy;
756 if (data.amtPolicy != null) { db.Put('amtPolicy', JSON.stringify(data.amtPolicy)); } else { db.Put('amtPolicy', null); }
757 - if (amt != null) { amt.setPolicy(amtPolicy); }
757 + if (amt != null) { amt.setPolicy(amtPolicy, true); }
758 break;
759 }
760 case 'getScript': {
@@ -1533,7 +1533,7 @@ function createMeshCore(agent)
1533 var response = null;
1534 switch (cmd) {
1535 case 'help': { // Displays available commands
1536 - response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm, amtdeactivate,\r\namtpolicy, getscript, getclip, setclip.';
1536 + response = 'Available commands: help, info, osinfo, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm,\r\namtdeactivate, amtpolicy, getscript, getclip, setclip.';
1537 break;
1538 }
1539 /*
@@ -2067,7 +2067,7 @@ function createMeshCore(agent)
2067 if (typeof text == 'object') { text = JSON.stringify(text); }
2068 mesh.SendCommand({ "action": "msg", "type": "console", "value": text, "sessionid": sessionid });
2069 }
2070 -
2070 +
2071 // Called before the process exits
2072 //process.exit = function (code) { console.log("Exit with code: " + code.toString()); }
2073
agents/modules_meshcore/amt-manage.js
+10 -28
@@ -42,10 +42,10 @@ function AmtManager(agent, db, isdebug) {
42 obj.setDebug = function (x) { isdebug = x; }
43
44 // Set current Intel AMT activation policy
45 - obj.setPolicy = function (policy) {
46 - if (JSON.stringify(amtpolicy) != JSON.stringify(policy)) {
45 + obj.setPolicy = function (policy, forceApply) {
46 + if (forceApply || (JSON.stringify(amtpolicy) != JSON.stringify(policy))) {
47 amtpolicy = policy;
48 - if (applyPolicyTimer == null) { obj.applyPolicy(); }
48 + if (applyPolicyTimer == null) { applyPolicyTimer = setTimeout(obj.applyPolicy, 8000); }
49 }
50 }
51
@@ -58,7 +58,7 @@ function AmtManager(agent, db, isdebug) {
58 try {
59 var amtMeiLib = require('amt-mei');
60 amtMei = new amtMeiLib();
61 - amtMei.on('error', function (e) { debug('MEI error'); amtMei = null; amtMeiState = -1; obj.state = -1; obj.onStateChange(amtMeiState); });
61 + amtMei.on('error', function (e) { debug('MEI error'); amtMei = null; amtMeiState = -1; obj.state = -1; if (obj.onStateChange != null) { obj.onStateChange(amtMeiState); } });
62 amtMei.getVersion(function (result) {
63 if (result == null) {
64 amtMeiState = -1;
@@ -455,11 +455,8 @@ function AmtManager(agent, db, isdebug) {
455 //
456
457 obj.activeToACM = function (mestate) {
458 - //debug('TrustedHashes: ' + JSON.stringify(trustedHashes));
459 - //debug('ProvisioningState: ' + JSON.stringify(mestate.ProvisioningState));
458 if ((mestate.ProvisioningState != 0) || (amtpolicy == null) || (amtpolicy.match == null)) return; // Can't activate unless in "PRE" activation mode & policy is present.
459 var trustedFqdn = null;
462 - //debug('Wired Interface: ' + JSON.stringify(mestate.net0));
460 if ((mestate.net0 == null) && (mestate.net0.enabled != 0)) return; // Can't activate unless wired interface is active
461 if (mestate.DNS) { trustedFqdn = mestate.DNS; } // If Intel AMT has a trusted DNS suffix set, use that one.
462 else {
@@ -471,41 +468,31 @@ function AmtManager(agent, db, isdebug) {
468 }
469 }
470 }
474 - //debug('TrustedFqdn: ' + trustedFqdn);
471 if (trustedFqdn == null) return; // No trusted DNS suffix.
472
473 // Check if we have a ACM policy match
474 var hashMatch = null;
475 for (var i in amtpolicy.match) { var m = amtpolicy.match[i]; if (m.cn == trustedFqdn) { for (var j in trustedHashes) { if ((trustedHashes[j] == m.sha256) || (trustedHashes[j] == m.sha1)) { hashMatch = trustedHashes[j]; } } } }
476 if (hashMatch == null) return; // No certificate / FQDN match
481 - //debug('Policy: ' + JSON.stringify(amtpolicy));
482 - //debug('HashMatch: ' + hashMatch);
477
478 // Fetch Intel AMT realm and activation nonce and get ready to ACM activation...
479 if (osamtstack != null) {
486 - //debug('Trying to get Intel AMT activation information (1)...');
480 osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToACM2, { fqdn: trustedFqdn, hash: hashMatch, uuid: mestate.UUID });
481 } else {
489 - //debug('ACM Activation: Trying to get local account info...');
482 amtMei.getLocalSystemAccount(function (x) {
483 if ((x != null) && x.user && x.pass) {
492 - //debug('Intel AMT local account info: User=' + x.user + ', Pass=' + x.pass + '.');
484 var transport = require('amt-wsman-duk');
485 var wsman = require('amt-wsman');
486 var amt = require('amt');
487 oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false);
488 osamtstack = new amt(oswsstack);
498 - //debug('Trying to get Intel AMT activation information (2)...');
489 osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToACM2, { fqdn: trustedFqdn, hash: hashMatch, uuid: mestate.UUID });
500 - } else {
501 - //debug('Unable to get $$OsAdmin password.');
490 }
491 });
492 }
493 }
494
495 function activeToACM2(stack, name, responses, status, tag) {
508 - //debug('activeToACM2 status=' + status);
496 if (status != 200) return;
497 var fwNonce = responses['IPS_HostBasedSetupService'].response['ConfigurationNonce'];
498 var digestRealm = responses['AMT_GeneralSettings'].response['DigestRealm'];
@@ -513,29 +500,24 @@ function AmtManager(agent, db, isdebug) {
500 }
501
502 // Called when the server responds with a ACM activation signature.
516 - obj.setAcmResponse = function (acmdata) {
517 - //debug('setAcmResponse=' + JSON.stringify(acmdata));
518 - acmdata.index = 0;
519 - performAcmActivation(acmdata);
520 - }
503 + obj.setAcmResponse = function (acmdata) { acmdata.index = 0; performAcmActivation(acmdata); }
504
505 // Recursive function to inject the provisioning certificates into AMT in the proper order and completes ACM activation
506 function performAcmActivation(acmdata) {
524 - //debug('performAcmActivation(' + JSON.stringify(acmdata) + ')');
507 var leaf = (acmdata.index == 0), root = (acmdata.index == (acmdata.certs.length - 1));
508 if ((acmdata.index < acmdata.certs.length) && (acmdata.certs[acmdata.index] != null)) {
527 - //debug('Calling AddNextCertInChain(' + acmdata.index + ', ' + acmdata.certs[acmdata.index] + ')');
509 osamtstack.IPS_HostBasedSetupService_AddNextCertInChain(acmdata.certs[acmdata.index], leaf, root, function (stack, name, responses, status) {
510 if (status !== 200) { debug('AddNextCertInChain status=' + status); return; }
511 else if (responses['Body']['ReturnValue'] !== 0) { debug('AddNextCertInChain error=' + responses['Body']['ReturnValue']); return; }
512 else { acmdata.index++; performAcmActivation(acmdata); }
513 });
514 } else {
534 - debug('Calling AdminSetup() ' + JSON.stringify(acmdata));
515 osamtstack.IPS_HostBasedSetupService_AdminSetup(2, acmdata.password, acmdata.nonce, 2, acmdata.signature,
516 function (stack, name, responses, status) {
537 - debug('AdminSetup Status: ' + status);
538 - if (status == 200) { debug('AdminSetup ReturnValue: ' + responses['Body']['ReturnValue']); }
517 + if ((status == 200) && (responses['Body']['ReturnValue'] == 0)) {
518 + // ACM activation success, force an update to the server so it can get our new state.
519 + if (obj.onStateChange != null) { obj.onStateChange(2); }
520 + }
521 }
522 );
523 }
@@ -628,7 +610,7 @@ function AmtManager(agent, db, isdebug) {
610 var wsmanQuery = ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService', '*AMT_RedirectionService', '*CIM_KVMRedirectionSAP', 'AMT_PublicKeyCertificate', '*AMT_EnvironmentDetectionSettingData'];
611 if (amtpolicy.cirasetup == 2) { wsmanQuery.push("AMT_ManagementPresenceRemoteSAP", "AMT_RemoteAccessCredentialContext", "AMT_RemoteAccessPolicyAppliesToMPS", "AMT_RemoteAccessPolicyRule", "*AMT_UserInitiatedConnectionService", "AMT_MPSUsernamePassword"); }
612 try { amtstack.BatchEnum(null, wsmanQuery, wsmanPassTestResponse); } catch (ex) { debug(ex); }
631 - } else if ((amtpolicy.type == 3) && (meinfo.ProvisioningState == 0)) {
613 + } else if ((amtpolicy.type == 3) && (meinfo.ProvisioningState == 0) && (agent.isControlChannelConnected)) {
614 // ACM Activation Policy
615 obj.getTrustedHashes(obj.activeToACM, meinfo);
616 } else {
agents/modules_meshcore_min/amt-manage.min.js
+1 -1
@@ -1 +1 @@
1 -function AmtManager(d,q,v){var M=function(T){d.SendCommand({action:"msg",type:"console",value:T})};var r=function(T){if(v){M("amt-manager: "+T+"<br />")}};var h=null,i=0;var f=null,g=0;var e=null;var H=null;var G=null;var k=null;var F=this;var E;var O=null;F.state=0;F.lmsstate=0;F.onStateChange=null;F.setDebug=function(T){v=T};F.setPolicy=function(T){if(JSON.stringify(k)!=JSON.stringify(T)){k=T;if(m==null){F.applyPolicy()}}};var L=0;F.reset=function(){++L;h=null,i=0,f=null,g=0,F.state=0,F.lmsstate=0;try{var T=require("amt-mei");h=new T();h.on("error",function(V){r("MEI error");h=null;i=-1;F.state=-1;F.onStateChange(i)});h.getVersion(function(V){if(V==null){i=-1;F.state=-1;if(F.onStateChange!=null){F.onStateChange(i)}if(L<10){setTimeout(F.reset,10000)}}else{e=V;i=2;F.state=2;L=0;if(F.onStateChange!=null){F.onStateChange(i)}F.lmsreset()}})}catch(U){r("MEI exception: "+U);h=null;i=-1;F.state=-1}};var j=null;F.getAmtInfo=function(U){if((h==null)||(i<2)){if(U!=null){U(null)}return}try{j={Flags:0};h.getProtocolVersion(function(V){if(V!=null){j.MeiVersion=V}});h.getVersion(function(V){if(V){j.Versions={};for(var W in V.Versions){j.Versions[V.Versions[W].Description]=V.Versions[W].Version}}});h.getProvisioningMode(function(V){if(V){j.ProvisioningMode=V.mode}});h.getProvisioningState(function(V){if(V){j.ProvisioningState=V.state}});h.getEHBCState(function(V){if((V!=null)&&(V.EHBC==true)){j.Flags+=1}});h.getControlMode(function(V){if(V!=null){if(V.controlMode==1){j.Flags+=2}if(V.controlMode==2){j.Flags+=4}}});h.getLanInterfaceSettings(0,function(V){if(V){j.net0=V}});h.getLanInterfaceSettings(1,function(V){if(V){j.net1=V}});h.getUuid(function(V){if((V!=null)&&(V.uuid!=null)){j.UUID=V.uuid}});h.getDnsSuffix(function(V){if(V!=null){j.DNS=V}if(U!=null){U(j)}})}catch(T){if(U!=null){U(null)}return}};var t=function(W){if((W==null)||(W.Body==null)||(W.Body.MessageID==null)||(W.Body.MessageArguments==null)){return null}var T=W.Body.MessageID,U=W.Body.MessageArguments[0],V=null;switch(T){case"iAMT0050":if(U=="48"){V="Intel&reg; AMT Serial-over-LAN connected"}else{if(U=="49"){V="Intel&reg; AMT Serial-over-LAN disconnected"}}break;case"iAMT0052":if(U=="1"){V="Intel&reg; AMT KVM connected"}else{if(U=="2"){V="Intel&reg; AMT KVM disconnected"}}break;default:break}if(V!=null){d.SendCommand({action:"msg",type:"notify",value:V,tag:"general"})}};F.lmsreset=function(){var T=null,U=0;F.lmsstate=0;try{var W=require("amt-lme");U=1;F.lmsstate=1;T=new W();T.on("error",function(X){U=0;F.lmsstate=0;T=null;r("LMS error");N(1)});T.on("connect",function(){U=2;F.lmsstate=2;r("LMS connected");N(2)});T.on("notify",function(Y,Z,aa,X){if(X=="iAMT0052-3"){y()}else{t(Y)}})}catch(V){U=-1;F.lmsstate=-1;T=null}};var N=function(T){if((h==null)||(i<2)||(e==null)){return}h.getLocalSystemAccount(function(aa){if(aa==null){return}var Y=require("amt-wsman-duk");var Z=require("amt-wsman");var U=require("amt");H=new Z(Y,"127.0.0.1",16992,aa.user,aa.pass,false);G=new U(H);i=3;F.state=3;if(F.onStateChange!=null){F.onStateChange(i)}if(m==null){F.applyPolicy()}var V=null;try{for(var X in e.Versions){if(e.Versions[X].Description=="AMT"){V=parseInt(e.Versions[X].Version.split(".")[0])}}}catch(W){}if((V!=null)&&(V>=12)){y("skip");F.kvmTempTimer=setInterval(function(){y()},2000);A(JSON.stringify({action:"restart",ver:1}))}})};var y=function(T){G.IPS_KVMRedirectionSettingData_DataChannelRead(F.kvmDataGetResponse,T)};var x=function(W,U,V,X,Y){if((Y!="skip")&&(X==200)&&(V.Body.ReturnValue==0)){var Z=null;try{Z=Buffer.from(V.Body.DataMessage,"base64").toString()}catch(T){return}if(Z!=null){F.kvmProcessData(V.Body.RealmsBitmap,V.Body.MessageId,Z)}}};var Q=null;var z=function(W,V,Y){var T=null;try{T=JSON.parse(Y)}catch(U){}if((T!=null)&&(T.action)){if(T.action=="present"){A(JSON.stringify({action:"present",ver:1,platform:process.platform}))}if(T.action=="offer"){Q={};var X=require("ILibWebRTC");Q.webrtc=X.createConnection();Q.webrtc.on("connected",function(){});Q.webrtc.on("disconnected",function(){F.webRtcCleanUp()});Q.webrtc.on("dataChannel",function(Z){Q.rtcchannel=Z;Q.kvm=mesh.getRemoteDesktopStream();Q.kvm.pipe(Q.rtcchannel,{dataTypeSkip:1,end:false});Q.rtcchannel.on("end",function(){F.webRtcCleanUp()});Q.rtcchannel.on("data",function(aa){F.kvmCtrlData(this,aa)});Q.rtcchannel.pipe(Q.kvm,{dataTypeSkip:1,end:false})});A(JSON.stringify({action:"answer",ver:1,sdp:Q.webrtc.setOffer(T.sdp)}))}}};var w=function(U,W){if(W.length>0&&W.charCodeAt(0)!=123){if(F.fileupload!=null){W=Buffer.from(W,"base64");var ac=W.readUInt32BE(0);if((ac==16777216)||(ac==16777217)){fs.writeSync(F.fileupload.fp,W.slice(4));U.write({action:"upload",sub:"ack",reqid:F.fileupload.reqid});if(ac==16777217){fs.closeSync(F.fileupload.fp);F.fileupload=null}}}return}r("KVM Ctrl Data: "+W);try{W=JSON.parse(W)}catch(Z){r("Invalid JSON: "+W);return}if((W.path!=null)&&(process.platform!="win32")&&(W.path[0]!="/")){W.path="/"+W.path}switch(W.action){case"ping":U.write({action:"pong"});break;case"lock":if(process.platform=="win32"){var V=require("child_process");V.execFile(process.env.windir+"\\system32\\cmd.exe",["/c","RunDll32.exe user32.dll,LockWorkStation"],{type:1})}break;case"ls":var af=getDirectoryInfo(W.path);if(W.reqid!=undefined){af.reqid=W.reqid}U.write(af);break;case"mkdir":fs.mkdirSync(W.path);break;case"rm":for(var ad in W.delfiles){var ab=I.join(W.path,W.delfiles[ad]);try{fs.unlinkSync(ab)}catch(Y){r(Y)}}break;case"rename":try{fs.renameSync(I.join(W.path,W.oldname),I.join(W.path,W.newname))}catch(Y){r(Y)}break;case"download":var ah=0;if(W.sub=="start"){if(F.filedownload!=null){U.write({action:"download",sub:"cancel",id:F.filedownload.id});delete F.filedownload}F.filedownload={id:W.id,path:W.path,ptr:0};try{F.filedownload.f=fs.openSync(F.filedownload.path,"rbN")}catch(Y){U.write({action:"download",sub:"cancel",id:F.filedownload.id});delete F.filedownload}if(F.filedownload){U.write({action:"download",sub:"start",id:W.id})}}else{if((F.filedownload!=null)&&(W.id==F.filedownload.id)){if(W.sub=="startack"){ah=8}else{if(W.sub=="stop"){delete F.filedownload}else{if(W.sub=="ack"){ah=1}}}}}while(ah>0){ah--;var T=Buffer.alloc(4096);var ae=fs.readSync(F.filedownload.f,T,4,4092,null);F.filedownload.ptr+=ae;if(ae<4092){T.writeInt32BE(16777217,0);fs.closeSync(F.filedownload.f);delete F.filedownload;ah=0}else{T.writeInt32BE(16777216,0)}U.write(T.slice(0,ae+4).toString("base64"))}break;case"upload":if(W.sub=="start"){if(F.fileupload!=null){fs.closeSync(F.fileupload.fp)}if(!W.path||!W.name){break}F.fileupload={reqid:W.reqid};var aa=I.join(W.path,W.name);try{F.fileupload.fp=fs.openSync(aa,"wbN")}catch(Y){}if(F.fileupload.fp){U.write({action:"upload",sub:"start",reqid:F.fileupload.reqid})}else{F.fileupload=null;U.write({action:"upload",sub:"error",reqid:F.fileupload.reqid})}}else{if(W.sub=="cancel"){if(F.fileupload!=null){fs.closeSync(F.fileupload.fp);F.fileupload=null}}}break;case"copy":for(var ad in W.names){var ag=I.join(W.scpath,W.names[ad]),X=I.join(W.dspath,W.names[ad]);if(ag!=X){try{fs.copyFileSync(ag,X)}catch(Y){}}}break;case"move":for(var ad in W.names){var ag=I.join(W.scpath,W.names[ad]),X=I.join(W.dspath,W.names[ad]);if(ag!=X){try{fs.copyFileSync(ag,X);fs.unlinkSync(ag)}catch(Y){}}}break;default:r("Invalid KVM command: "+W);break}};var P=function(){r("webRtcCleanUp");if(Q==null){return}if(Q.rtcchannel){try{Q.rtcchannel.close()}catch(T){}try{Q.rtcchannel.removeAllListeners("data")}catch(T){}try{Q.rtcchannel.removeAllListeners("end")}catch(T){}delete Q.rtcchannel}if(Q.webrtc){try{Q.webrtc.close()}catch(T){}try{Q.webrtc.removeAllListeners("connected")}catch(T){}try{Q.webrtc.removeAllListeners("disconnected")}catch(T){}try{Q.webrtc.removeAllListeners("dataChannel")}catch(T){}delete Q.webrtc}if(Q.kvm){try{Q.kvm.end()}catch(T){}delete Q.kvm}Q=null};var A=function(T){G.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(T).toString("base64"),function(){})};var s=function(T,U){if(fs.existsSync(T)){if(U==true){fs.readdirSync(F.path.join(T,"*")).forEach(function(W,X){var V=F.path.join(T,W);if(fs.statSync(V).isDirectory()){s(V,true)}else{fs.unlinkSync(V)}})}fs.unlinkSync(T)}};var I={join:function(){var V=[];for(var T in arguments){var U=arguments[T];if(U!=null){while(U.endsWith("/")||U.endsWith("\\")){U=U.substring(0,U.length-1)}if(T!=0){while(U.startsWith("/")||U.startsWith("\\")){U=U.substring(1)}}V.push(U)}}if(V.length==0){return"/"}return V.join("/")}};function D(T){return require("MD5Stream").create().syncHash(T).toString("hex")}F.deactivateCCM=function(){h.unprovision(1,function(T){if(T==0){r("Success deactivating Intel AMT CCM.");d.SendCommand({action:"coreinfo",intelamt:{state:0,flags:0}});m=setTimeout(F.applyPolicy,8000)}else{r("Intel AMT CCM deactivation error: "+T)}})};F.getTrustedHashes=function(T,U){if(O!=null){T(U)}O=[];h.getHashHandles(function(W){var V=W.length;for(var X=0;X<W.length;++X){this.getCertHashEntry(W[X],function(Y){if(Y.isActive==1){O.push(Y.certificateHash.toLowerCase())}if(--V==0){T(U)}})}})};F.activeToACM=function(Y){if((Y.ProvisioningState!=0)||(k==null)||(k.match==null)){return}var Z=null;if((Y.net0==null)&&(Y.net0.enabled!=0)){return}if(Y.DNS){Z=Y.DNS}else{var V=require("os").networkInterfaces();for(var U in V){for(var W in V[U]){if((V[U][W].mac==Y.net0.mac)&&(V[U][W].fqdn!=null)&&(V[U][W].fqdn!="")){Z=V[U][W].fqdn.toLowerCase()}}}}if(Z==null){return}var T=null;for(var U in k.match){var X=k.match[U];if(X.cn==Z){for(var W in O){if((O[W]==X.sha256)||(O[W]==X.sha1)){T=O[W]}}}}if(T==null){return}if(G!=null){G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],a,{fqdn:Z,hash:T})}else{h.getLocalSystemAccount(function(ad){if((ad!=null)&&ad.user&&ad.pass){var ab=require("amt-wsman-duk");var ac=require("amt-wsman");var aa=require("amt");H=new ac(ab,"127.0.0.1",16992,ad.user,ad.pass,false);G=new aa(H);G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],a,{fqdn:Z,hash:T})}else{}})}};function a(X,V,W,Y,Z){if(Y!=200){return}var U=W.IPS_HostBasedSetupService.response.ConfigurationNonce;var T=W.AMT_GeneralSettings.response.DigestRealm;d.SendCommand({action:"acmactivate",nonce:U,realm:T,fqdn:Z.fqdn,hash:Z.hash})}F.setAcmResponse=function(T){T.index=0;J(T)};function J(T){var U=(T.index==0),V=(T.index==(T.certs.length-1));if((T.index<T.certs.length)&&(T.certs[T.index]!=null)){G.IPS_HostBasedSetupService_AddNextCertInChain(T.certs[T.index],U,V,function(Y,W,X,Z){if(Z!==200){r("AddNextCertInChain status="+Z);return}else{if(X.Body["ReturnValue"]!==0){r("AddNextCertInChain error="+X.Body["ReturnValue"]);return}else{T.index++;J(T)}}})}else{r("Calling AdminSetup() "+JSON.stringify(T));G.IPS_HostBasedSetupService_AdminSetup(2,T.password,T.nonce,2,T.signature,function(Y,W,X,Z){r("AdminSetup Status: "+Z);if(Z==200){r("AdminSetup ReturnValue: "+X.Body["ReturnValue"])}})}}function B(U){var W="",V="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var T=0;T<U;T++){W+=V.charAt(Math.floor(Math.random()*V.length))}return W}F.activeToCCM=function(T){if((T==null)||(T=="")){T="P@0s"+B(23)}u=T;if(G!=null){G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],b,T)}else{h.getLocalSystemAccount(function(X){if((X!=null)&&X.user&&X.pass){var V=require("amt-wsman-duk");var W=require("amt-wsman");var U=require("amt");H=new W(V,"127.0.0.1",16992,X.user,X.pass,false);G=new U(H);G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],b,T)}else{}})}};var b=function(W,U,V,X,T){if(X!=200){r("Failed to fetch activation information, status "+X)}else{if(V.IPS_HostBasedSetupService.response.AllowedControlModes.length!=2){r("Client control mode activation not allowed")}else{W.IPS_HostBasedSetupService_Setup(2,D("admin:"+V.AMT_GeneralSettings.response.DigestRealm+":"+T).substring(0,32),null,null,null,null,c)}}};var c=function(V,T,U,W){if(W!=200){r("Failed to activate, status "+W)}else{if(U.Body.ReturnValue!=0){r("Client control mode activation failed: "+U.Body.ReturnValueStr)}else{r("Intel AMT CCM activation success.");q.Put("amtCCMPass",u);d.SendCommand({action:"coreinfo",intelamt:{state:2,flags:2,user:"admin",pass:u}})}}m=setTimeout(F.applyPolicy,8000)};F.start=function(){var T=null;try{T=JSON.parse(q.Get("amtPolicy"))}catch(U){r("Exception loading amtPolicy")}try{u=q.Get("amtCCMPass")}catch(U){}if(typeof u!="string"){u=null}F.reset()};var u,S,l,m,K=0;F.applyPolicy=function(){m=null;if((i!=3)||(k==null)||(typeof k!="object")||(typeof k.type!="number")||(k.type==0)){return}if((k.password!=null)&&(k.password!="")){u=k.password}F.getAmtInfo(function(V){if((k.type==1)&&(V.ProvisioningState==2)&&((V.Flags&2)!=0)){S=l=null;F.deactivateCCM()}else{if((k.type==2)&&(V.ProvisioningState==0)){S=l=null;if((k.password==null)||(k.password=="")){u=null}F.activeToCCM(u)}else{if((k.type==2)&&(V.ProvisioningState==2)&&(u!=null)&&((V.Flags&2)!=0)){var W=require("amt-wsman-duk");var X=require("amt-wsman");var T=require("amt");S=new X(W,"127.0.0.1",16992,"admin",u,false);l=new T(S);var Y=["*AMT_GeneralSettings","*IPS_HostBasedSetupService","*AMT_RedirectionService","*CIM_KVMRedirectionSAP","AMT_PublicKeyCertificate","*AMT_EnvironmentDetectionSettingData"];if(k.cirasetup==2){Y.push("AMT_ManagementPresenceRemoteSAP","AMT_RemoteAccessCredentialContext","AMT_RemoteAccessPolicyAppliesToMPS","AMT_RemoteAccessPolicyRule","*AMT_UserInitiatedConnectionService","AMT_MPSUsernamePassword")}try{l.BatchEnum(null,Y,R)}catch(U){r(U)}}else{if((k.type==3)&&(V.ProvisioningState==0)){F.getTrustedHashes(F.activeToACM,V)}else{}}}}})};function R(ab,V,X,ac){if(ac!=200){if(ac==401){if(k.badpass==1){F.deactivateCCM()}}else{if(++K<20){if(K==10){r("WSMAN fault, MEI Reset");F.reset()}var ad=["*AMT_GeneralSettings","*IPS_HostBasedSetupService","*AMT_RedirectionService","*CIM_KVMRedirectionSAP","AMT_PublicKeyCertificate","*AMT_EnvironmentDetectionSettingData"];if(k.cirasetup==2){ad.push("AMT_ManagementPresenceRemoteSAP","AMT_RemoteAccessCredentialContext","AMT_RemoteAccessPolicyAppliesToMPS","AMT_RemoteAccessPolicyRule","*AMT_UserInitiatedConnectionService","AMT_MPSUsernamePassword")}try{l.BatchEnum(null,ad,R)}catch(T){r(T)}}else{r("WSMAN fault, status="+ac);K=0}}}else{K=0;var Z={};Z.redir=(X.AMT_RedirectionService.response.ListenerEnabled==true);Z.sol=((X.AMT_RedirectionService.response.EnabledState&2)!=0);Z.ider=((X.AMT_RedirectionService.response.EnabledState&1)!=0);Z.kvm=(X.CIM_KVMRedirectionSAP!=null)&&((X.CIM_KVMRedirectionSAP.response.EnabledState==6&&X.CIM_KVMRedirectionSAP.response.RequestedState==2)||X.CIM_KVMRedirectionSAP.response.EnabledState==2||X.CIM_KVMRedirectionSAP.response.EnabledState==6);if((X.AMT_GeneralSettings.response.PingResponseEnabled!=true)||(X.AMT_GeneralSettings.response.RmcpPingResponseEnabled!=true)){X.AMT_GeneralSettings.response.PingResponseEnabled=true;X.AMT_GeneralSettings.response.RmcpPingResponseEnabled=true;l.Put("AMT_GeneralSettings",X.AMT_GeneralSettings.response,function(ai,ag,ah,aj){if(aj!=200){r("Enable PING PUT Error "+aj)}},0,1)}if((Z.redir==false)||(Z.sol==false)||(Z.ider==false)){var W=X.AMT_RedirectionService.response;W.ListenerEnabled=true;W.EnabledState=32768+1+2;l.AMT_RedirectionService_RequestStateChange(W.EnabledState,function(ai,ag,ah,aj){if(aj!=200){r("Enable Redirection EXEC Error "+aj)}})}if((X.CIM_KVMRedirectionSAP!=null)&&(Z.kvm==false)){l.CIM_KVMRedirectionSAP_RequestStateChange(2,0,function(ai,ag,ah,aj){if(aj!=200){messagebox("Error","KVMRedirectionSAP, RequestStateChange Error "+aj);return}l.Put("AMT_RedirectionService",W,function(am,ak,al,an){if(an!=200){r("Enable KVM PUT Error "+an)}},0,1)})}if(typeof k.rootcert=="string"){var Y=false,ae=X.AMT_PublicKeyCertificate.responses;for(var U in ae){if((ae[U]["X509Certificate"]==k.rootcert)&&(ae[U]["TrustedRootCertficate"]==true)){Y=true}}if(Y==false){l.AMT_PublicKeyManagementService_AddTrustedRootCertificate(k.rootcert,function(ai,ag,ah,aj){if(aj!=200){r("Add root cert EXEC Error "+aj)}})}}if((k.cirasetup==2)&&(k.ciraserver!=null)){var aa=false,af=X.AMT_ManagementPresenceRemoteSAP.responses;for(var U in af){if((af[U].AccessInfo==k.ciraserver.name)&&(af[U].Port==k.ciraserver.port)){aa=af[U].Name}}if(aa==false){l.AMT_RemoteAccessService_AddMpServer(k.ciraserver.name,201,k.ciraserver.port,2,null,k.ciraserver.user,k.ciraserver.pass,null,function(aj,ah,ai,ak){if(ak!=200){r("Add MPS server EXEC Error "+ak)}else{aa=false;var al=ai.Body.MpServer.ReferenceParameters.SelectorSet.Selector;for(var ag in al){if(al[ag]["@Name"]=="Name"){aa=al[ag]["Value"]}}if(aa!=false){n(X,aa)}}})}else{n(X,aa)}}else{if(k.cirasetup==1){o(X)}}}}function n(T,V){var U='<Address xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</Address><ReferenceParameters xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing"><ResourceURI xmlns="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">http://intel.com/wbem/wscim/1/amt-schema/1/AMT_ManagementPresenceRemoteSAP</ResourceURI><SelectorSet xmlns="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"><Selector Name="Name">'+V+"</Selector></SelectorSet></ReferenceParameters>";l.AMT_RemoteAccessService_AddRemoteAccessPolicyRule(2,0,"AAAAAAAAAAo=",[U],null,function(Y,W,X,Z){if(Z!=200){r("Add AddRemoteAccessPolicyRule Error "+Z)}else{o(T)}})}function o(T){var V=[];if((k.ciraserver!=null)&&(k.ciraserver.home!=null)){V=k.ciraserver.home}var U=T.AMT_EnvironmentDetectionSettingData.response;U.DetectionStrings=C(U.DetectionStrings);if(p(U.DetectionStrings,V)==false){U.DetectionStrings=V;l.Put("AMT_EnvironmentDetectionSettingData",U,function(Y,W,X,Z){if(Z!=200){r("Put AMT_EnvironmentDetectionSettingData Error "+Z)}},0,1)}}function p(T,U){if(T==U){return true}if(T==null){T=[]}if(U==null){U=[]}if(T.length!=U.length){return false}for(var V in T){if(U.indexOf(T[V])==-1){return false}}return true}function C(T){if(!T||T==null||typeof T=="object"){return T}return[T]}}module.exports=AmtManager;
\ No newline at end of file
1 +function AmtManager(d,q,v){var M=function(T){d.SendCommand({action:"msg",type:"console",value:T})};var r=function(T){if(v){M("amt-manager: "+T+"<br />")}};var h=null,i=0;var f=null,g=0;var e=null;var H=null;var G=null;var k=null;var F=this;var E;var O=null;F.state=0;F.lmsstate=0;F.onStateChange=null;F.setDebug=function(T){v=T};F.setPolicy=function(U,T){if(T||(JSON.stringify(k)!=JSON.stringify(U))){k=U;if(m==null){m=setTimeout(F.applyPolicy,8000)}}};var L=0;F.reset=function(){++L;h=null,i=0,f=null,g=0,F.state=0,F.lmsstate=0;try{var T=require("amt-mei");h=new T();h.on("error",function(V){r("MEI error");h=null;i=-1;F.state=-1;if(F.onStateChange!=null){F.onStateChange(i)}});h.getVersion(function(V){if(V==null){i=-1;F.state=-1;if(F.onStateChange!=null){F.onStateChange(i)}if(L<10){setTimeout(F.reset,10000)}}else{e=V;i=2;F.state=2;L=0;if(F.onStateChange!=null){F.onStateChange(i)}F.lmsreset()}})}catch(U){r("MEI exception: "+U);h=null;i=-1;F.state=-1}};var j=null;F.getAmtInfo=function(U){if((h==null)||(i<2)){if(U!=null){U(null)}return}try{j={Flags:0};h.getProtocolVersion(function(V){if(V!=null){j.MeiVersion=V}});h.getVersion(function(V){if(V){j.Versions={};for(var W in V.Versions){j.Versions[V.Versions[W].Description]=V.Versions[W].Version}}});h.getProvisioningMode(function(V){if(V){j.ProvisioningMode=V.mode}});h.getProvisioningState(function(V){if(V){j.ProvisioningState=V.state}});h.getEHBCState(function(V){if((V!=null)&&(V.EHBC==true)){j.Flags+=1}});h.getControlMode(function(V){if(V!=null){if(V.controlMode==1){j.Flags+=2}if(V.controlMode==2){j.Flags+=4}}});h.getLanInterfaceSettings(0,function(V){if(V){j.net0=V}});h.getLanInterfaceSettings(1,function(V){if(V){j.net1=V}});h.getUuid(function(V){if((V!=null)&&(V.uuid!=null)){j.UUID=V.uuid}});h.getDnsSuffix(function(V){if(V!=null){j.DNS=V}if(U!=null){U(j)}})}catch(T){if(U!=null){U(null)}return}};var t=function(W){if((W==null)||(W.Body==null)||(W.Body.MessageID==null)||(W.Body.MessageArguments==null)){return null}var T=W.Body.MessageID,U=W.Body.MessageArguments[0],V=null;switch(T){case"iAMT0050":if(U=="48"){V="Intel&reg; AMT Serial-over-LAN connected"}else{if(U=="49"){V="Intel&reg; AMT Serial-over-LAN disconnected"}}break;case"iAMT0052":if(U=="1"){V="Intel&reg; AMT KVM connected"}else{if(U=="2"){V="Intel&reg; AMT KVM disconnected"}}break;default:break}if(V!=null){d.SendCommand({action:"msg",type:"notify",value:V,tag:"general"})}};F.lmsreset=function(){var T=null,U=0;F.lmsstate=0;try{var W=require("amt-lme");U=1;F.lmsstate=1;T=new W();T.on("error",function(X){U=0;F.lmsstate=0;T=null;r("LMS error");N(1)});T.on("connect",function(){U=2;F.lmsstate=2;r("LMS connected");N(2)});T.on("notify",function(Y,Z,aa,X){if(X=="iAMT0052-3"){y()}else{t(Y)}})}catch(V){U=-1;F.lmsstate=-1;T=null}};var N=function(T){if((h==null)||(i<2)||(e==null)){return}h.getLocalSystemAccount(function(aa){if(aa==null){return}var Y=require("amt-wsman-duk");var Z=require("amt-wsman");var U=require("amt");H=new Z(Y,"127.0.0.1",16992,aa.user,aa.pass,false);G=new U(H);i=3;F.state=3;if(F.onStateChange!=null){F.onStateChange(i)}if(m==null){F.applyPolicy()}var V=null;try{for(var X in e.Versions){if(e.Versions[X].Description=="AMT"){V=parseInt(e.Versions[X].Version.split(".")[0])}}}catch(W){}if((V!=null)&&(V>=12)){y("skip");F.kvmTempTimer=setInterval(function(){y()},2000);A(JSON.stringify({action:"restart",ver:1}))}})};var y=function(T){G.IPS_KVMRedirectionSettingData_DataChannelRead(F.kvmDataGetResponse,T)};var x=function(W,U,V,X,Y){if((Y!="skip")&&(X==200)&&(V.Body.ReturnValue==0)){var Z=null;try{Z=Buffer.from(V.Body.DataMessage,"base64").toString()}catch(T){return}if(Z!=null){F.kvmProcessData(V.Body.RealmsBitmap,V.Body.MessageId,Z)}}};var Q=null;var z=function(W,V,Y){var T=null;try{T=JSON.parse(Y)}catch(U){}if((T!=null)&&(T.action)){if(T.action=="present"){A(JSON.stringify({action:"present",ver:1,platform:process.platform}))}if(T.action=="offer"){Q={};var X=require("ILibWebRTC");Q.webrtc=X.createConnection();Q.webrtc.on("connected",function(){});Q.webrtc.on("disconnected",function(){F.webRtcCleanUp()});Q.webrtc.on("dataChannel",function(Z){Q.rtcchannel=Z;Q.kvm=mesh.getRemoteDesktopStream();Q.kvm.pipe(Q.rtcchannel,{dataTypeSkip:1,end:false});Q.rtcchannel.on("end",function(){F.webRtcCleanUp()});Q.rtcchannel.on("data",function(aa){F.kvmCtrlData(this,aa)});Q.rtcchannel.pipe(Q.kvm,{dataTypeSkip:1,end:false})});A(JSON.stringify({action:"answer",ver:1,sdp:Q.webrtc.setOffer(T.sdp)}))}}};var w=function(U,W){if(W.length>0&&W.charCodeAt(0)!=123){if(F.fileupload!=null){W=Buffer.from(W,"base64");var ac=W.readUInt32BE(0);if((ac==16777216)||(ac==16777217)){fs.writeSync(F.fileupload.fp,W.slice(4));U.write({action:"upload",sub:"ack",reqid:F.fileupload.reqid});if(ac==16777217){fs.closeSync(F.fileupload.fp);F.fileupload=null}}}return}r("KVM Ctrl Data: "+W);try{W=JSON.parse(W)}catch(Z){r("Invalid JSON: "+W);return}if((W.path!=null)&&(process.platform!="win32")&&(W.path[0]!="/")){W.path="/"+W.path}switch(W.action){case"ping":U.write({action:"pong"});break;case"lock":if(process.platform=="win32"){var V=require("child_process");V.execFile(process.env.windir+"\\system32\\cmd.exe",["/c","RunDll32.exe user32.dll,LockWorkStation"],{type:1})}break;case"ls":var af=getDirectoryInfo(W.path);if(W.reqid!=undefined){af.reqid=W.reqid}U.write(af);break;case"mkdir":fs.mkdirSync(W.path);break;case"rm":for(var ad in W.delfiles){var ab=I.join(W.path,W.delfiles[ad]);try{fs.unlinkSync(ab)}catch(Y){r(Y)}}break;case"rename":try{fs.renameSync(I.join(W.path,W.oldname),I.join(W.path,W.newname))}catch(Y){r(Y)}break;case"download":var ah=0;if(W.sub=="start"){if(F.filedownload!=null){U.write({action:"download",sub:"cancel",id:F.filedownload.id});delete F.filedownload}F.filedownload={id:W.id,path:W.path,ptr:0};try{F.filedownload.f=fs.openSync(F.filedownload.path,"rbN")}catch(Y){U.write({action:"download",sub:"cancel",id:F.filedownload.id});delete F.filedownload}if(F.filedownload){U.write({action:"download",sub:"start",id:W.id})}}else{if((F.filedownload!=null)&&(W.id==F.filedownload.id)){if(W.sub=="startack"){ah=8}else{if(W.sub=="stop"){delete F.filedownload}else{if(W.sub=="ack"){ah=1}}}}}while(ah>0){ah--;var T=Buffer.alloc(4096);var ae=fs.readSync(F.filedownload.f,T,4,4092,null);F.filedownload.ptr+=ae;if(ae<4092){T.writeInt32BE(16777217,0);fs.closeSync(F.filedownload.f);delete F.filedownload;ah=0}else{T.writeInt32BE(16777216,0)}U.write(T.slice(0,ae+4).toString("base64"))}break;case"upload":if(W.sub=="start"){if(F.fileupload!=null){fs.closeSync(F.fileupload.fp)}if(!W.path||!W.name){break}F.fileupload={reqid:W.reqid};var aa=I.join(W.path,W.name);try{F.fileupload.fp=fs.openSync(aa,"wbN")}catch(Y){}if(F.fileupload.fp){U.write({action:"upload",sub:"start",reqid:F.fileupload.reqid})}else{F.fileupload=null;U.write({action:"upload",sub:"error",reqid:F.fileupload.reqid})}}else{if(W.sub=="cancel"){if(F.fileupload!=null){fs.closeSync(F.fileupload.fp);F.fileupload=null}}}break;case"copy":for(var ad in W.names){var ag=I.join(W.scpath,W.names[ad]),X=I.join(W.dspath,W.names[ad]);if(ag!=X){try{fs.copyFileSync(ag,X)}catch(Y){}}}break;case"move":for(var ad in W.names){var ag=I.join(W.scpath,W.names[ad]),X=I.join(W.dspath,W.names[ad]);if(ag!=X){try{fs.copyFileSync(ag,X);fs.unlinkSync(ag)}catch(Y){}}}break;default:r("Invalid KVM command: "+W);break}};var P=function(){r("webRtcCleanUp");if(Q==null){return}if(Q.rtcchannel){try{Q.rtcchannel.close()}catch(T){}try{Q.rtcchannel.removeAllListeners("data")}catch(T){}try{Q.rtcchannel.removeAllListeners("end")}catch(T){}delete Q.rtcchannel}if(Q.webrtc){try{Q.webrtc.close()}catch(T){}try{Q.webrtc.removeAllListeners("connected")}catch(T){}try{Q.webrtc.removeAllListeners("disconnected")}catch(T){}try{Q.webrtc.removeAllListeners("dataChannel")}catch(T){}delete Q.webrtc}if(Q.kvm){try{Q.kvm.end()}catch(T){}delete Q.kvm}Q=null};var A=function(T){G.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(T).toString("base64"),function(){})};var s=function(T,U){if(fs.existsSync(T)){if(U==true){fs.readdirSync(F.path.join(T,"*")).forEach(function(W,X){var V=F.path.join(T,W);if(fs.statSync(V).isDirectory()){s(V,true)}else{fs.unlinkSync(V)}})}fs.unlinkSync(T)}};var I={join:function(){var V=[];for(var T in arguments){var U=arguments[T];if(U!=null){while(U.endsWith("/")||U.endsWith("\\")){U=U.substring(0,U.length-1)}if(T!=0){while(U.startsWith("/")||U.startsWith("\\")){U=U.substring(1)}}V.push(U)}}if(V.length==0){return"/"}return V.join("/")}};function D(T){return require("MD5Stream").create().syncHash(T).toString("hex")}F.deactivateCCM=function(){h.unprovision(1,function(T){if(T==0){r("Success deactivating Intel AMT CCM.");d.SendCommand({action:"coreinfo",intelamt:{state:0,flags:0}});m=setTimeout(F.applyPolicy,8000)}else{r("Intel AMT CCM deactivation error: "+T)}})};F.getTrustedHashes=function(T,U){if(O!=null){T(U)}O=[];h.getHashHandles(function(W){var V=W.length;for(var X=0;X<W.length;++X){this.getCertHashEntry(W[X],function(Y){if(Y.isActive==1){O.push(Y.certificateHash.toLowerCase())}if(--V==0){T(U)}})}})};F.activeToACM=function(Y){if((Y.ProvisioningState!=0)||(k==null)||(k.match==null)){return}var Z=null;if((Y.net0==null)&&(Y.net0.enabled!=0)){return}if(Y.DNS){Z=Y.DNS}else{var V=require("os").networkInterfaces();for(var U in V){for(var W in V[U]){if((V[U][W].mac==Y.net0.mac)&&(V[U][W].fqdn!=null)&&(V[U][W].fqdn!="")){Z=V[U][W].fqdn.toLowerCase()}}}}if(Z==null){return}var T=null;for(var U in k.match){var X=k.match[U];if(X.cn==Z){for(var W in O){if((O[W]==X.sha256)||(O[W]==X.sha1)){T=O[W]}}}}if(T==null){return}if(G!=null){G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],a,{fqdn:Z,hash:T,uuid:Y.UUID})}else{h.getLocalSystemAccount(function(ad){if((ad!=null)&&ad.user&&ad.pass){var ab=require("amt-wsman-duk");var ac=require("amt-wsman");var aa=require("amt");H=new ac(ab,"127.0.0.1",16992,ad.user,ad.pass,false);G=new aa(H);G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],a,{fqdn:Z,hash:T,uuid:Y.UUID})}})}};function a(X,V,W,Y,Z){if(Y!=200){return}var U=W.IPS_HostBasedSetupService.response.ConfigurationNonce;var T=W.AMT_GeneralSettings.response.DigestRealm;d.SendCommand({action:"acmactivate",nonce:U,realm:T,fqdn:Z.fqdn,hash:Z.hash,uuid:Z.uuid})}F.setAcmResponse=function(T){T.index=0;J(T)};function J(T){var U=(T.index==0),V=(T.index==(T.certs.length-1));if((T.index<T.certs.length)&&(T.certs[T.index]!=null)){G.IPS_HostBasedSetupService_AddNextCertInChain(T.certs[T.index],U,V,function(Y,W,X,Z){if(Z!==200){r("AddNextCertInChain status="+Z);return}else{if(X.Body["ReturnValue"]!==0){r("AddNextCertInChain error="+X.Body["ReturnValue"]);return}else{T.index++;J(T)}}})}else{G.IPS_HostBasedSetupService_AdminSetup(2,T.password,T.nonce,2,T.signature,function(Y,W,X,Z){if((Z==200)&&(X.Body["ReturnValue"]==0)){if(F.onStateChange!=null){F.onStateChange(2)}}})}}function B(U){var W="",V="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var T=0;T<U;T++){W+=V.charAt(Math.floor(Math.random()*V.length))}return W}F.activeToCCM=function(T){if((T==null)||(T=="")){T="P@0s"+B(23)}u=T;if(G!=null){G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],b,T)}else{h.getLocalSystemAccount(function(X){if((X!=null)&&X.user&&X.pass){var V=require("amt-wsman-duk");var W=require("amt-wsman");var U=require("amt");H=new W(V,"127.0.0.1",16992,X.user,X.pass,false);G=new U(H);G.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],b,T)}else{}})}};var b=function(W,U,V,X,T){if(X!=200){r("Failed to fetch activation information, status "+X)}else{if(V.IPS_HostBasedSetupService.response.AllowedControlModes.length!=2){r("Client control mode activation not allowed")}else{W.IPS_HostBasedSetupService_Setup(2,D("admin:"+V.AMT_GeneralSettings.response.DigestRealm+":"+T).substring(0,32),null,null,null,null,c)}}};var c=function(V,T,U,W){if(W!=200){r("Failed to activate, status "+W)}else{if(U.Body.ReturnValue!=0){r("Client control mode activation failed: "+U.Body.ReturnValueStr)}else{r("Intel AMT CCM activation success.");q.Put("amtCCMPass",u);d.SendCommand({action:"coreinfo",intelamt:{state:2,flags:2,user:"admin",pass:u}})}}m=setTimeout(F.applyPolicy,8000)};F.start=function(){var T=null;try{T=JSON.parse(q.Get("amtPolicy"))}catch(U){r("Exception loading amtPolicy")}try{u=q.Get("amtCCMPass")}catch(U){}if(typeof u!="string"){u=null}F.reset()};var u,S,l,m,K=0;F.applyPolicy=function(){m=null;if((i!=3)||(k==null)||(typeof k!="object")||(typeof k.type!="number")||(k.type==0)){return}if((k.password!=null)&&(k.password!="")){u=k.password}F.getAmtInfo(function(V){if((k.type==1)&&(V.ProvisioningState==2)&&((V.Flags&2)!=0)){S=l=null;F.deactivateCCM()}else{if((k.type==2)&&(V.ProvisioningState==0)){S=l=null;if((k.password==null)||(k.password=="")){u=null}F.activeToCCM(u)}else{if((k.type==2)&&(V.ProvisioningState==2)&&(u!=null)&&((V.Flags&2)!=0)){var W=require("amt-wsman-duk");var X=require("amt-wsman");var T=require("amt");S=new X(W,"127.0.0.1",16992,"admin",u,false);l=new T(S);var Y=["*AMT_GeneralSettings","*IPS_HostBasedSetupService","*AMT_RedirectionService","*CIM_KVMRedirectionSAP","AMT_PublicKeyCertificate","*AMT_EnvironmentDetectionSettingData"];if(k.cirasetup==2){Y.push("AMT_ManagementPresenceRemoteSAP","AMT_RemoteAccessCredentialContext","AMT_RemoteAccessPolicyAppliesToMPS","AMT_RemoteAccessPolicyRule","*AMT_UserInitiatedConnectionService","AMT_MPSUsernamePassword")}try{l.BatchEnum(null,Y,R)}catch(U){r(U)}}else{if((k.type==3)&&(V.ProvisioningState==0)&&(d.isControlChannelConnected)){F.getTrustedHashes(F.activeToACM,V)}else{}}}}})};function R(ab,V,X,ac){if(ac!=200){if(ac==401){if(k.badpass==1){F.deactivateCCM()}}else{if(++K<20){if(K==10){r("WSMAN fault, MEI Reset");F.reset()}var ad=["*AMT_GeneralSettings","*IPS_HostBasedSetupService","*AMT_RedirectionService","*CIM_KVMRedirectionSAP","AMT_PublicKeyCertificate","*AMT_EnvironmentDetectionSettingData"];if(k.cirasetup==2){ad.push("AMT_ManagementPresenceRemoteSAP","AMT_RemoteAccessCredentialContext","AMT_RemoteAccessPolicyAppliesToMPS","AMT_RemoteAccessPolicyRule","*AMT_UserInitiatedConnectionService","AMT_MPSUsernamePassword")}try{l.BatchEnum(null,ad,R)}catch(T){r(T)}}else{r("WSMAN fault, status="+ac);K=0}}}else{K=0;var Z={};Z.redir=(X.AMT_RedirectionService.response.ListenerEnabled==true);Z.sol=((X.AMT_RedirectionService.response.EnabledState&2)!=0);Z.ider=((X.AMT_RedirectionService.response.EnabledState&1)!=0);Z.kvm=(X.CIM_KVMRedirectionSAP!=null)&&((X.CIM_KVMRedirectionSAP.response.EnabledState==6&&X.CIM_KVMRedirectionSAP.response.RequestedState==2)||X.CIM_KVMRedirectionSAP.response.EnabledState==2||X.CIM_KVMRedirectionSAP.response.EnabledState==6);if((X.AMT_GeneralSettings.response.PingResponseEnabled!=true)||(X.AMT_GeneralSettings.response.RmcpPingResponseEnabled!=true)){X.AMT_GeneralSettings.response.PingResponseEnabled=true;X.AMT_GeneralSettings.response.RmcpPingResponseEnabled=true;l.Put("AMT_GeneralSettings",X.AMT_GeneralSettings.response,function(ai,ag,ah,aj){if(aj!=200){r("Enable PING PUT Error "+aj)}},0,1)}if((Z.redir==false)||(Z.sol==false)||(Z.ider==false)){var W=X.AMT_RedirectionService.response;W.ListenerEnabled=true;W.EnabledState=32768+1+2;l.AMT_RedirectionService_RequestStateChange(W.EnabledState,function(ai,ag,ah,aj){if(aj!=200){r("Enable Redirection EXEC Error "+aj)}})}if((X.CIM_KVMRedirectionSAP!=null)&&(Z.kvm==false)){l.CIM_KVMRedirectionSAP_RequestStateChange(2,0,function(ai,ag,ah,aj){if(aj!=200){messagebox("Error","KVMRedirectionSAP, RequestStateChange Error "+aj);return}l.Put("AMT_RedirectionService",W,function(am,ak,al,an){if(an!=200){r("Enable KVM PUT Error "+an)}},0,1)})}if(typeof k.rootcert=="string"){var Y=false,ae=X.AMT_PublicKeyCertificate.responses;for(var U in ae){if((ae[U]["X509Certificate"]==k.rootcert)&&(ae[U]["TrustedRootCertficate"]==true)){Y=true}}if(Y==false){l.AMT_PublicKeyManagementService_AddTrustedRootCertificate(k.rootcert,function(ai,ag,ah,aj){if(aj!=200){r("Add root cert EXEC Error "+aj)}})}}if((k.cirasetup==2)&&(k.ciraserver!=null)){var aa=false,af=X.AMT_ManagementPresenceRemoteSAP.responses;for(var U in af){if((af[U].AccessInfo==k.ciraserver.name)&&(af[U].Port==k.ciraserver.port)){aa=af[U].Name}}if(aa==false){l.AMT_RemoteAccessService_AddMpServer(k.ciraserver.name,201,k.ciraserver.port,2,null,k.ciraserver.user,k.ciraserver.pass,null,function(aj,ah,ai,ak){if(ak!=200){r("Add MPS server EXEC Error "+ak)}else{aa=false;var al=ai.Body.MpServer.ReferenceParameters.SelectorSet.Selector;for(var ag in al){if(al[ag]["@Name"]=="Name"){aa=al[ag]["Value"]}}if(aa!=false){n(X,aa)}}})}else{n(X,aa)}}else{if(k.cirasetup==1){o(X)}}}}function n(T,V){var U='<Address xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</Address><ReferenceParameters xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing"><ResourceURI xmlns="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">http://intel.com/wbem/wscim/1/amt-schema/1/AMT_ManagementPresenceRemoteSAP</ResourceURI><SelectorSet xmlns="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"><Selector Name="Name">'+V+"</Selector></SelectorSet></ReferenceParameters>";l.AMT_RemoteAccessService_AddRemoteAccessPolicyRule(2,0,"AAAAAAAAAAo=",[U],null,function(Y,W,X,Z){if(Z!=200){r("Add AddRemoteAccessPolicyRule Error "+Z)}else{o(T)}})}function o(T){var V=[];if((k.ciraserver!=null)&&(k.ciraserver.home!=null)){V=k.ciraserver.home}var U=T.AMT_EnvironmentDetectionSettingData.response;U.DetectionStrings=C(U.DetectionStrings);if(p(U.DetectionStrings,V)==false){U.DetectionStrings=V;l.Put("AMT_EnvironmentDetectionSettingData",U,function(Y,W,X,Z){if(Z!=200){r("Put AMT_EnvironmentDetectionSettingData Error "+Z)}},0,1)}}function p(T,U){if(T==U){return true}if(T==null){T=[]}if(U==null){U=[]}if(T.length!=U.length){return false}for(var V in T){if(U.indexOf(T[V])==-1){return false}}return true}function C(T){if(!T||T==null||typeof T=="object"){return T}return[T]}}module.exports=AmtManager;
\ No newline at end of file
views/default-min.handlebars
+6 -2
@@ -12417,7 +12417,8 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
12417 function p20editMeshAmtChange() {
12418 var ptype = Q('dp20amtpolicy').value, x = '';
12419 if (ptype >= 2) {
12420 - x = addHtmlValue('Password*', '<input id=dp20amtpolicypass style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
12420 + x = addHtmlValue('Password*', '<input id=dp20amtpolicypass type=password style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
12421 + x += addHtmlValue('Password*', '<input id=dp20amtpolicypass2 type=password style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
12422 if (ptype == 2) { x += addHtmlValue('Password mismatch', "<select id=dp20amtbadpass style=width:230px><option value=0>Do nothing</option><option value=1>Reactivate Intel&reg; AMT</option></select>"); }
12423 if ((features & 0x400) == 0) {
12424 if (ptype == 2) {
@@ -12439,7 +12440,10 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
12440
12441 function dp20amtValidatePolicy() {
12442 var ok = true, ptype = Q('dp20amtpolicy').value;
12442 - if (ptype == 2) { var pass = Q('dp20amtpolicypass').value; ok = (pass == '') ? true : passwordcheck(pass); }
12443 + if ((ptype == 2) || (ptype == 3)) {
12444 + var pass = Q('dp20amtpolicypass').value, pass2 = Q('dp20amtpolicypass2').value;
12445 + ok = ((pass === pass2) && ((pass === '') ? true : passwordcheck(pass)));
12446 + }
12447 QE('idx_dlgOkButton', ok);
12448 }
12449
views/default.handlebars
+6 -2
@@ -6362,7 +6362,8 @@
6362 function p20editMeshAmtChange() {
6363 var ptype = Q('dp20amtpolicy').value, x = '';
6364 if (ptype >= 2) {
6365 - x = addHtmlValue('Password*', '<input id=dp20amtpolicypass style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
6365 + x = addHtmlValue('Password*', '<input id=dp20amtpolicypass type=password style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
6366 + x += addHtmlValue('Password*', '<input id=dp20amtpolicypass2 type=password style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
6367 if (ptype == 2) { x += addHtmlValue('Password mismatch', "<select id=dp20amtbadpass style=width:230px><option value=0>Do nothing</option><option value=1>Reactivate Intel&reg; AMT</option></select>"); }
6368 if ((features & 0x400) == 0) {
6369 if (ptype == 2) {
@@ -6384,7 +6385,10 @@
6385
6386 function dp20amtValidatePolicy() {
6387 var ok = true, ptype = Q('dp20amtpolicy').value;
6387 - if (ptype == 2) { var pass = Q('dp20amtpolicypass').value; ok = (pass == '') ? true : passwordcheck(pass); }
6388 + if ((ptype == 2) || (ptype == 3)) {
6389 + var pass = Q('dp20amtpolicypass').value, pass2 = Q('dp20amtpolicypass2').value;
6390 + ok = ((pass === pass2) && ((pass === '') ? true : passwordcheck(pass)));
6391 + }
6392 QE('idx_dlgOkButton', ok);
6393 }
6394